diff options
author | Martin Fischer <martin@push-f.com> | 2024-12-12 08:14:18 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2024-12-12 08:14:18 +0100 |
commit | d17efc051d99e27abd44655acaf508e360c41bac (patch) | |
tree | f83607c9378403270c9aca1f682a06cec7bb741b | |
parent | 2cac94f9c3aa9797a8b86921cb01c96eee013a7f (diff) |
refactor: move part-specifics out of .zshrc
-rw-r--r-- | nixos/parts/dev.nix | 5 | ||||
-rw-r--r-- | nixos/parts/graphical.nix | 5 | ||||
-rw-r--r-- | user/zsh/.zshrc | 26 | ||||
-rw-r--r-- | user/zsh/zshrc-dev.sh | 11 | ||||
-rw-r--r-- | user/zsh/zshrc-graphical.sh | 16 |
5 files changed, 43 insertions, 20 deletions
diff --git a/nixos/parts/dev.nix b/nixos/parts/dev.nix index e2ac1f6..aca8e78 100644 --- a/nixos/parts/dev.nix +++ b/nixos/parts/dev.nix @@ -1,6 +1,11 @@ { config, pkgs, ... }: { + environment.sessionVariables = { + # Tell .zshrc to source zshrc-dev.sh. + MYNIX_DEV = "true"; + }; + environment.systemPackages = with pkgs; [ rustup python313 diff --git a/nixos/parts/graphical.nix b/nixos/parts/graphical.nix index a032ddf..990cd9e 100644 --- a/nixos/parts/graphical.nix +++ b/nixos/parts/graphical.nix @@ -8,6 +8,11 @@ }; programs.ssh.startAgent = true; + environment.sessionVariables = { + # Tell .zshrc to source zshrc-graphical.sh. + MYNIX_GRAPHICAL = "true"; + }; + environment.systemPackages = with pkgs; [ # CLI tools brightnessctl diff --git a/user/zsh/.zshrc b/user/zsh/.zshrc index ba07dc2..a579784 100644 --- a/user/zsh/.zshrc +++ b/user/zsh/.zshrc @@ -22,9 +22,7 @@ function ls() { } ## Aliases -alias code='codium' alias ls='ls --color=auto --group-directories-first' # see also ls function -alias tokei='tokei -s code -n commas' alias tree='tree -aI .git --dirsfirst' ## Shell variables @@ -52,7 +50,6 @@ export XDG_CONFIG_HOME=$HOME/.config export EDITOR=vim export INPUTRC=$XDG_CONFIG_HOME/readline/inputrc -export NPM_CONFIG_PREFIX="$HOME/.local/npm" export PYTHON_BASIC_REPL=1 # use readline (Python >=3.13 defaults to its own REPL which has no vi keybindings) # If we'd extend the PATH with PATH=$PATH:extra the PATH would become longer with each subshell. @@ -60,26 +57,15 @@ export PYTHON_BASIC_REPL=1 # use readline (Python >=3.13 defaults to its own REP typeset -U path PATH # Now we can append PATH entries with path+=... without the PATH growing in each subshell. -path+=~/.cargo/bin -path+=($NPM_CONFIG_PREFIX/bin) - ## Completion autoload -Uz compinit [ -d "$XDG_CACHE_HOME"/zsh ] || mkdir -p "$XDG_CACHE_HOME"/zsh compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-$ZSH_VERSION -# Terminal emulator specifics -if [ $TERM = foot ]; then - # Enable spawning of new terminal instances in the current working directory - function osc7-pwd() { - emulate -L zsh # also sets localoptions for us - setopt extendedglob - local LC_ALL=C - printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}} - } - - function chpwd-osc7-pwd() { - (( ZSH_SUBSHELL )) || osc7-pwd - } - add-zsh-hook -Uz chpwd chpwd-osc7-pwd +# Environment-specifics +if [ -n "$MYNIX_DEV" ]; then + source "$ZDOTDIR/zshrc-dev.sh" +fi +if [ -n "$MYNIX_GRAPHICAL" ]; then + source "$ZDOTDIR/zshrc-graphical.sh" fi diff --git a/user/zsh/zshrc-dev.sh b/user/zsh/zshrc-dev.sh new file mode 100644 index 0000000..484007d --- /dev/null +++ b/user/zsh/zshrc-dev.sh @@ -0,0 +1,11 @@ +# This file is sourced by .zshrc if parts/dev.nix was imported. + +## Aliases +alias code='codium' +alias tokei='tokei -s code -n commas' + +## Environment variables +export NPM_CONFIG_PREFIX="$HOME/.local/npm" + +path+=~/.cargo/bin +path+=($NPM_CONFIG_PREFIX/bin) diff --git a/user/zsh/zshrc-graphical.sh b/user/zsh/zshrc-graphical.sh new file mode 100644 index 0000000..d60c15a --- /dev/null +++ b/user/zsh/zshrc-graphical.sh @@ -0,0 +1,16 @@ +# This file is sourced by .zshrc if parts/graphical.nix was imported. + +if [ $TERM = foot ]; then + # Enable spawning of new terminal instances in the current working directory + function osc7-pwd() { + emulate -L zsh # also sets localoptions for us + setopt extendedglob + local LC_ALL=C + printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}} + } + + function chpwd-osc7-pwd() { + (( ZSH_SUBSHELL )) || osc7-pwd + } + add-zsh-hook -Uz chpwd chpwd-osc7-pwd +fi |