From d17efc051d99e27abd44655acaf508e360c41bac Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 12 Dec 2024 08:14:18 +0100 Subject: refactor: move part-specifics out of .zshrc --- user/zsh/.zshrc | 26 ++++++-------------------- user/zsh/zshrc-dev.sh | 11 +++++++++++ user/zsh/zshrc-graphical.sh | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 user/zsh/zshrc-dev.sh create mode 100644 user/zsh/zshrc-graphical.sh (limited to 'user/zsh') 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 -- cgit v1.2.3