From b61387adc936dc51f1d9e84136aa9972ea8480e7 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sat, 1 Aug 2026 17:29:55 +0200 Subject: zsh: Schreibweise für Funktionen und 'source' vereinheitlicht MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsh/zprofile | 10 ++++++++-- zsh/zshrc | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/zsh/zprofile b/zsh/zprofile index cfb0fbb..7fed3a7 100644 --- a/zsh/zprofile +++ b/zsh/zprofile @@ -1,9 +1,13 @@ # vim: filetype=zsh -[[ -d "${HISTFILE:h}" ]] || mkdir -p "${HISTFILE:h}" +if [[ ! -d "${HISTFILE:h}" ]]; then + mkdir -p "${HISTFILE:h}" +fi add_path() { - [[ -d "$1" ]] && path=("$1" $path) + if [[ -d "$1" ]]; then + path=("$1" $path) + fi } set_include_lib_path() { @@ -57,3 +61,5 @@ if [[ -x /usr/local/bin/musicpd ]] && ! pgrep "musicpd" > /dev/null; then /usr/local/bin/musicpd fi +unfunction add_path +unfunction set_include_lib_path diff --git a/zsh/zshrc b/zsh/zshrc index 7d8d675..fd04552 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,7 +1,7 @@ # vim: filetype=zsh # Hooks -function chpwd() { +chpwd() { if [[ -n "$VIRTUAL_ENV" && -f "$VIRTUAL_ENV/bin/activate" ]]; then local venv_dir="${VIRTUAL_ENV:h}" if [[ "$PWD" != "$venv_dir"* ]] && (( $+functions[deactivate] )); then @@ -11,15 +11,17 @@ function chpwd() { for v in .venv venv .env; do if [[ -f "$v/bin/activate" ]]; then - source "$v/bin/activate" + . "$v/bin/activate" break fi done } # Funktionen -function source_file() { - [[ ! -r "$1" ]] || source "$1" +source_if_exists() { + if [[ -r "$1" ]]; then + . "$1" + fi } # Optionen @@ -31,16 +33,16 @@ setopt SHARE_HISTORY setopt HIST_IGNORE_ALL_DUPS setopt HIST_IGNORE_SPACE -source_file "$HOME/.opam/opam-init/init.zsh" +source_if_exists "$HOME/.opam/opam-init/init.zsh" case "$OSTYPE" in darwin*) - source_file "/opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" - source_file "/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh" + source_if_exists "/opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + source_if_exists "/opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ;; freebsd*) - source_file "/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" - source_file "/usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" + source_if_exists "/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + source_if_exists "/usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ;; esac @@ -86,12 +88,13 @@ nvim-update() { } # Command completion -autoload -U compinit; compinit +autoload -U compinit +compinit _comp_options+=(globdots) # With hidden files # ... Angular CLI if (( $+commands[ng] )); then - source <(ng completion script) + . <(ng completion script) fi zstyle ':completion:*' completer _extensions _complete _approximate @@ -119,3 +122,5 @@ zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%a%u%c%F{3}|%F{1}%a%F{5}]%f' zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%u%c%F{5}]%f' zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' + +unfunction source_if_exists -- cgit v1.3