zsh: split zshrc into dedicated file

This commit is contained in:
2025-07-16 00:24:38 +00:00
parent fde708e602
commit cbcb43ac2c
3 changed files with 84 additions and 78 deletions

View File

@@ -53,83 +53,7 @@ in
".local/share/zsh"
];
fs.".config/zsh/.zshrc".symlink.text = ''
# zsh/prezto complains if zshrc doesn't exist or is empty;
# preserve this comment to prevent that from ever happening.
HISTFILE="$HOME/.local/share/zsh/history"
HISTSIZE=1000000
SAVEHIST=1000000
# auto-cd into any of these dirs by typing them and pressing 'enter':
hash -d 3rd="/home/colin/dev/3rd"
hash -d dev="/home/colin/dev"
hash -d knowledge="/home/colin/knowledge"
hash -d nixos="/home/colin/nixos"
hash -d nixpkgs="/home/colin/dev/3rd/nixpkgs"
hash -d ref="/home/colin/ref"
hash -d secrets="/home/colin/knowledge/secrets"
hash -d tmp="/home/colin/tmp"
hash -d uninsane="/home/colin/dev/uninsane"
hash -d Videos="/home/colin/Videos"
# emulate bash keybindings
bindkey -e
# emulate vim keybindings (a.k.a. `setopt VI`)
# bindkey -v
# fixup bindings not handled by bash, see: <https://wiki.archlinux.org/title/Zsh#Key_bindings>
# `bindkey -e` seems to define most of the `key` array. everything in the Arch defaults except for these:
if [[ -z "''${key[Backspace]}" ]]; then
key[Backspace]="''${terminfo[kbs]}"
fi
if [[ -z "''${key[Control-Left]}" ]]; then
key[Control-Left]="''${terminfo[kLFT5]}"
fi
if [[ -z "''${key[Control-Right]}" ]]; then
key[Control-Right]="''${terminfo[kRIT5]}"
fi
if [[ -z "''${key[Shift-Tab]}" ]]; then
key[Shift-Tab]="''${terminfo[kcbt]}"
fi
# XXX(2025-04-12): Control-Left and Control-Right sometimes _still_ don't exist (e.g. raw TTYs, ssh).
# build them from `^` + `Left` instead:
if [[ -z "''${key[Left]}" ]]; then
key[Left]="''${terminfo[kcub1]}"
fi
if [[ -z "''${key[Right]}" ]]; then
key[Right]="''${terminfo[kcuf1]}"
fi
if [[ -z "''${key[Control-Left]}" ]] && [[ -n "''${key[Left]}" ]]; then
key[Control-Left]="^''${key[Left]}"
fi
if [[ -z "''${key[Control-Right]}" ]] && [[ -n "''${key[Right]}" ]]; then
key[Control-Right]="^''${key[Right]}"
fi
bindkey -- "''${key[Delete]}" delete-char
bindkey -- "''${key[Control-Left]}" backward-word
bindkey -- "''${key[Control-Right]}" forward-word
# or manually recreate what i care about...
# key[Left]=''${terminfo[kcub1]}
# key[Right]=''${terminfo[kcuf1]}
# bindkey '^R' history-incremental-search-backward
# bindkey '^A' beginning-of-line
# bindkey '^E' end-of-line
# bindkey "^''${key[Left]}" backward-word
# bindkey "^''${key[Right]}" forward-word
# disable "flow control" (Ctrl+S to suspend terminal, Ctrl+Q to resume).
# see: <https://forum.endeavouros.com/t/alacritty-flow-control-turn-off/6199/12>
stty -ixon
# run any additional, sh-generic commands (useful for e.g. launching a login manager on login)
if [[ -e ~/.profile ]]; then
source ~/.profile
fi
'';
fs.".config/zsh/.zshrc".symlink.target = ./zshrc;
};

View File

@@ -17,7 +17,7 @@ let
};
in {
sane.programs.zsh.fs = lib.mkIf enabled {
".config/zsh/.zshrc".symlink.text = ''
".config/zsh/rc.d/10-starship".symlink.text = ''
eval "$(${lib.getExe pkgs.starship} init zsh)"
'';
".config/starship.toml".symlink.target = let

View File

@@ -0,0 +1,82 @@
# zsh/prezto complains if zshrc doesn't exist or is empty;
# preserve this comment to prevent that from ever happening.
HISTFILE="$HOME/.local/share/zsh/history"
HISTSIZE=1000000
SAVEHIST=1000000
# auto-cd into any of these dirs by typing them and pressing 'enter':
hash -d 3rd="/home/colin/dev/3rd"
hash -d dev="/home/colin/dev"
hash -d knowledge="/home/colin/knowledge"
hash -d nixos="/home/colin/nixos"
hash -d nixpkgs="/home/colin/dev/3rd/nixpkgs"
hash -d ref="/home/colin/ref"
hash -d secrets="/home/colin/knowledge/secrets"
hash -d tmp="/home/colin/tmp"
hash -d uninsane="/home/colin/dev/uninsane"
hash -d Videos="/home/colin/Videos"
# emulate bash keybindings
bindkey -e
# emulate vim keybindings (a.k.a. `setopt VI`)
# bindkey -v
# fixup bindings not handled by bash, see: <https://wiki.archlinux.org/title/Zsh#Key_bindings>
# `bindkey -e` seems to define most of the `key` array. everything in the Arch defaults except for these:
if [[ -z "${key[Backspace]}" ]]; then
key[Backspace]="${terminfo[kbs]}"
fi
if [[ -z "${key[Control-Left]}" ]]; then
key[Control-Left]="${terminfo[kLFT5]}"
fi
if [[ -z "${key[Control-Right]}" ]]; then
key[Control-Right]="${terminfo[kRIT5]}"
fi
if [[ -z "${key[Shift-Tab]}" ]]; then
key[Shift-Tab]="${terminfo[kcbt]}"
fi
# XXX(2025-04-12): Control-Left and Control-Right sometimes _still_ don't exist (e.g. raw TTYs, ssh).
# build them from `^` + `Left` instead:
if [[ -z "${key[Left]}" ]]; then
key[Left]="${terminfo[kcub1]}"
fi
if [[ -z "${key[Right]}" ]]; then
key[Right]="${terminfo[kcuf1]}"
fi
if [[ -z "${key[Control-Left]}" ]] && [[ -n "${key[Left]}" ]]; then
key[Control-Left]="^${key[Left]}"
fi
if [[ -z "${key[Control-Right]}" ]] && [[ -n "${key[Right]}" ]]; then
key[Control-Right]="^${key[Right]}"
fi
bindkey -- "${key[Delete]}" delete-char
bindkey -- "${key[Control-Left]}" backward-word
bindkey -- "${key[Control-Right]}" forward-word
# or manually recreate what i care about...
# key[Left]=${terminfo[kcub1]}
# key[Right]=${terminfo[kcuf1]}
# bindkey '^R' history-incremental-search-backward
# bindkey '^A' beginning-of-line
# bindkey '^E' end-of-line
# bindkey "^${key[Left]}" backward-word
# bindkey "^${key[Right]}" forward-word
# disable "flow control" (Ctrl+S to suspend terminal, Ctrl+Q to resume).
# see: <https://forum.endeavouros.com/t/alacritty-flow-control-turn-off/6199/12>
stty -ixon
# allow extensions (e.g. starship) to hook zsh startup
# `(N)` at the end of a glob means to not error on zero matches
for f in ~/.config/zsh/rc.d/*(N); do
source "$f"
done
# run any additional, sh-generic commands (useful for e.g. launching a login manager on login)
if [[ -e ~/.profile ]]; then
source ~/.profile
fi