home: create 'modules/home' folder

Consolidating all modules under the same path, to clear out the
top-level directory.
This commit is contained in:
Bruno BELANYI 2023-11-09 13:43:55 +00:00
parent c856933803
commit 65a8f7c481
119 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,35 @@
# shellcheck shell=bash
# Style the completion a bit
# shellcheck disable=2086,2296
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# Show a prompt on selection
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
# Use arrow keys in completion list
zstyle ':completion:*' menu select
# Group results by category
zstyle ':completion:*' group-name ''
# Keep directories and files separated
zstyle ':completion:*' list-dirs-first true
# Expand '//' to '/'
zstyle ':completion:*' squeeze-slashes true
# Add colors to processes for kill completion
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.old' '*?.pro'
# command for process lists, the local web server details and host completion
# on processes completion complete all user processes
# shellcheck disable=2016
zstyle ':completion:*:processes' command 'ps -au$USER'
# Completion formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'

View file

@ -0,0 +1,95 @@
{ config, pkgs, lib, ... }:
let
cfg = config.my.home.zsh;
# Have a nice relative path for XDG_CONFIG_HOME, without leading `/`
relativeXdgConfig =
let
noHome = lib.removePrefix config.home.homeDirectory;
noSlash = lib.removePrefix "/";
in
noSlash (noHome config.xdg.configHome);
in
{
options.my.home.zsh = with lib; {
enable = my.mkDisableOption "zsh configuration";
launchTmux = mkEnableOption "auto launch tmux at shell start";
};
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [
zsh-completions
];
programs.zsh = {
enable = true;
dotDir = "${relativeXdgConfig}/zsh"; # Don't clutter $HOME
enableCompletion = true;
history = {
size = 500000;
save = 500000;
extended = true;
expireDuplicatesFirst = true;
ignoreSpace = true;
ignoreDups = true;
share = false;
path = "${config.xdg.dataHome}/zsh/zsh_history";
};
plugins = [
{
name = "fast-syntax-highlighting";
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
src = pkgs.zsh-fast-syntax-highlighting;
}
{
name = "agkozak-zsh-prompt";
file = "share/zsh/site-functions/agkozak-zsh-prompt.plugin.zsh";
src = pkgs.agkozak-zsh-prompt;
}
];
# Modal editing is life, but CLI benefits from emacs gymnastics
defaultKeymap = "emacs";
# Make those happen early to avoid doing double the work
initExtraFirst = ''
${
lib.optionalString cfg.launchTmux ''
# Launch tmux unless already inside one
if [ -z "$TMUX" ]; then
exec tmux new-session
fi
''
}
'';
initExtra = ''
source ${./completion-styles.zsh}
source ${./extra-mappings.zsh}
source ${./options.zsh}
# Source local configuration
if [ -f "$ZDOTDIR/zshrc.local" ]; then
source "$ZDOTDIR/zshrc.local"
fi
'';
localVariables = {
# I like having the full path
AGKOZAK_PROMPT_DIRTRIM = 0;
# Because I *am* from EPITA
AGKOZAK_PROMPT_CHAR = [ "42sh$" "42sh#" ":" ];
# Easy on the eyes
AGKOZAK_COLORS_BRANCH_STATUS = "magenta";
# I don't like moving my eyes
AGKOZAK_LEFT_PROMPT_ONLY = 1;
};
# Enable VTE integration
enableVteIntegration = true;
};
};
}

View file

@ -0,0 +1,132 @@
# shellcheck shell=bash
# Fix Ctrl+u killing from the cursor instead of the whole line
bindkey '^u' backward-kill-line
# Use Ctrl+x-(Ctrl+)e to edit the current command line in VISUAL/EDITOR
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
# The expression: (( ${+terminfo} )) should never fail, but does if we
# don't have a tty, perhaps due to a bug in the zsh/terminfo module.
if ! { [ "$TERM" != emacs ] && (( ${+terminfo} )) 2>/dev/null; }; then
return
fi
# Make sure that the terminal is in application mode when zle is active, since
# only then values from $terminfo are valid
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
zle_application_mode_start() { echoti smkx; }
zle_application_mode_stop() { echoti rmkx; }
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi
# Fix delete key not working
if [ -n "${terminfo[kdch1]}" ]; then
bindkey -M emacs "${terminfo[kdch1]}" delete-char
bindkey -M viins "${terminfo[kdch1]}" delete-char
bindkey -M vicmd "${terminfo[kdch1]}" delete-char
else
bindkey -M emacs "^[[3~" delete-char
bindkey -M viins "^[[3~" delete-char
bindkey -M vicmd "^[[3~" delete-char
bindkey -M emacs "^[3;5~" delete-char
bindkey -M viins "^[3;5~" delete-char
bindkey -M vicmd "^[3;5~" delete-char
fi
# Ctrl-Delete to delete a whole word forward
if [ -n "${terminfo[kdl1]}" ]; then
bindkey -M emacs "${terminfo[kdl1]}" kill-word
bindkey -M viins "${terminfo[kdl1]}" kill-word
bindkey -M vicmd "${terminfo[kdl1]}" kill-word
else
bindkey -M emacs '^[[3;5~' kill-word
bindkey -M viins '^[[3;5~' kill-word
bindkey -M vicmd '^[[3;5~' kill-word
fi
# Enable Shift-Tab to go backwards in completion list
if [ -n "${terminfo[kcbt]}" ]; then
bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete
bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
else
bindkey -M emacs '^[[Z' reverse-menu-complete
bindkey -M viins '^[[Z' reverse-menu-complete
bindkey -M vicmd '^[[Z' reverse-menu-complete
fi
# Ctrl-Left moves backward one word
if [ -n "${terminfo[kLFT5]}" ]; then
bindkey -M emacs "${terminfo[kLFT5]}" backward-word
bindkey -M viins "${terminfo[kLFT5]}" backward-word
bindkey -M vicmd "${terminfo[kLFT5]}" backward-word
else
bindkey -M emacs '^[[1;5D' backward-word
bindkey -M viins '^[[1;5D' backward-word
bindkey -M vicmd '^[[1;5D' backward-word
fi
# Ctrl-Right moves forward one word
if [ -n "${terminfo[kRIT5]}" ]; then
bindkey -M emacs "${terminfo[kRIT5]}" forward-word
bindkey -M viins "${terminfo[kRIT5]}" forward-word
bindkey -M vicmd "${terminfo[kRIT5]}" forward-word
else
bindkey -M emacs '^[[1;5C' forward-word
bindkey -M viins '^[[1;5C' forward-word
bindkey -M vicmd '^[[1;5C' forward-word
fi
# PageUp goes backwards in history
if [ -n "${terminfo[kpp]}" ]; then
bindkey -M emacs "${terminfo[kpp]}" up-line-or-history
bindkey -M viins "${terminfo[kpp]}" up-line-or-history
bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history
else
bindkey -M emacs "^[[5~" up-line-or-history
bindkey -M viins "^[[5~" up-line-or-history
bindkey -M vicmd "^[[5~" up-line-or-history
fi
# PageDown goes forward in history
if [ -n "${terminfo[knp]}" ]; then
bindkey -M emacs "${terminfo[knp]}" down-line-or-history
bindkey -M viins "${terminfo[knp]}" down-line-or-history
bindkey -M vicmd "${terminfo[knp]}" down-line-or-history
else
bindkey -M emacs "^[[6~" down-line-or-history
bindkey -M viins "^[[6~" down-line-or-history
bindkey -M vicmd "^[[6~" down-line-or-history
fi
# Home goes to the beginning of the line
if [ -n "${terminfo[khome]}" ]; then
bindkey -M emacs "${terminfo[khome]}" beginning-of-line
bindkey -M viins "${terminfo[khome]}" beginning-of-line
bindkey -M vicmd "${terminfo[khome]}" beginning-of-line
else
bindkey -M emacs "^[[1~" beginning-of-line
bindkey -M viins "^[[1~" beginning-of-line
bindkey -M vicmd "^[[1~" beginning-of-line
fi
# End goes to the end of the line
if [ -n "${terminfo[kend]}" ]; then
bindkey -M emacs "${terminfo[kend]}" end-of-line
bindkey -M viins "${terminfo[kend]}" end-of-line
bindkey -M vicmd "${terminfo[kend]}" end-of-line
else
bindkey -M emacs "^[[4~" end-of-line
bindkey -M viins "^[[4~" end-of-line
bindkey -M vicmd "^[[4~" end-of-line
fi

View file

@ -0,0 +1,20 @@
# shellcheck shell=bash
# Show an error when a globbing expansion doesn't find any match
setopt nomatch
# List on ambiguous completion and Insert first match immediately
setopt auto_list menu_complete
# Use pushd when cd-ing around
setopt auto_pushd pushd_minus pushd_silent
# Use single quotes in string without the weird escape tricks
setopt rc_quotes
# Single word commands can resume an existing job
setopt auto_resume
# Show history expansion before running a command
setopt hist_verify
# Append commands to history as they are exectuted
setopt inc_append_history_time
# Remove useless whitespace from commands
setopt hist_reduce_blanks
# Those options aren't wanted
unsetopt beep extended_glob notify