Procházet zdrojové kódy

fix(zsh): include defaults from `/etc/` and protect `$PATH` from `path_helper`

Joe před 1 rokem
rodič
revize
daa5a21bd7
2 změnil soubory, kde provedl 79 přidání a 53 odebrání
  1. 58 32
      .config/zsh/.zshenv
  2. 21 21
      .config/zsh/.zshrc

+ 58 - 32
.config/zsh/.zshenv

@@ -1,40 +1,64 @@
+################################################################################
+# ZSH Configuration
+#
+# Note: in order for files in `~/.config` to be picked up, be sure to set the
+# global `XDG_*` and `ZDOTDIR` paths. On macOS, these are set at `/etc/zshenv`
+# or `~/.zshenv`), and look something like the following block:
+#
+# ```zsh
+# export XDG_CONFIG_HOME=$HOME/.config
+# export XDG_CACHE_HOME=$HOME/.cache
+# export XDG_DATA_HOME=$HOME/.local/share
+# export XDG_STATE_HOME=$HOME/.local/state
+# export XDG_RUNTIME_DIR=$HOME/.run
+# export XDG_DATA_DIRS=/usr/local/share:/usr/share
+# export XDG_CONFIG_DIRS=/etc/xdg
+# export ZDOTDIR=$XDG_CONFIG_HOME/zsh
+# if [ -f $ZDOTDIR/.zshenv ]; then source $ZDOTDIR/.zshenv; fi
+# ```
+#
+################################################################################
+
+################################################################################
+# Disable /etc/zprofile, /etc/zshrc, /etc/zlogin and /etc/zlogout
+################################################################################
+unsetopt GLOBAL_RCS
+
 ################################################################################
 ################################################################################
 # $PATH and similar
 # $PATH and similar
 ################################################################################
 ################################################################################
-export GOPATH="$HOME/.go"
-# Add to path without duplicates
-function add_to_path {
-    if [[ ! ":$PATH:" == *":$1:"* ]]; then
-        if [ "$2" = true ] ; then
-            PATH=":$1:$PATH:"
-        else
-            PATH="$PATH:$1:"
-        fi
-        PATH=${PATH/::/:/.}
-        if [[ "$PATH" == ":"* ]]; then
-            PATH="${PATH:1}"
-        fi
-        if [[ "$PATH" == *":" ]]; then
-            PATH="${PATH::-1}"
-        fi
-    fi
-}
+PATH="/bin:/sbin"
 
 
-add_to_path "/usr/local/bin/" true
-add_to_path "/opt/homebrew/sbin" true
-add_to_path "/opt/homebrew/bin" true
+PATH="${PATH}:/usr/local/bin"
+PATH="${PATH}:/opt/homebrew/sbin"
+PATH="${PATH}:/opt/homebrew/bin"
+
+PATH="${PATH}:/usr/bin"
+PATH="${PATH}:/usr/sbin"
 
 
 # Additional Homebrew items that aren't linked by default
 # Additional Homebrew items that aren't linked by default
-add_to_path "/opt/homebrew/opt/ruby/bin"
-add_to_path "/opt/homebrew/opt/libpq/bin"
+PATH="${PATH}:/opt/homebrew/opt/ruby/bin"
+PATH="${PATH}:/opt/homebrew/opt/libpq/bin"
+
+PATH="${PATH}:${HOME}/.scripts"
+
+export GOPATH="${HOME}/.go"
 
 
-add_to_path "${HOME}/.scripts"
+PATH="${PATH}:${GOPATH}/bin"
+PATH="${PATH}:${HOME}/.gem/bin"
+PATH="${PATH}:${HOME}/.cargo/bin"
+PATH="${PATH}:${HOME}/.poetry/bin"
+PATH="${PATH}:${HOME}/.rvm/bin"
 
 
-add_to_path "${GOPATH}/bin"
-add_to_path "${HOME}/.gem/bin"
-add_to_path "${HOME}/.cargo/bin"
-add_to_path "${HOME}/.poetry/bin"
-add_to_path "${HOME}/.rvm/bin"
+# Run `path_helper`, and make its entries appear last, to preserve path ordering
+if [ -x /usr/libexec/path_helper ]; then
+    oldpath="${PATH}"
+    eval `/usr/libexec/path_helper -s`
+    PATH="${oldpath}:${PATH}"
+fi
+
+# Remove duplicate entries
+typeset -U PATH
 
 
 export PATH
 export PATH
 
 
@@ -85,8 +109,8 @@ alias c="clear && NEW_LINE_BEFORE_PROMPT=0"
 alias clear="clear && NEW_LINE_BEFORE_PROMPT=0"
 alias clear="clear && NEW_LINE_BEFORE_PROMPT=0"
 
 
 #python
 #python
-alias python="python3.13"
-alias py="python3.13"
+alias python="python3"
+alias py="python3"
 
 
 #granted
 #granted
 alias assume=". assume"
 alias assume=". assume"
@@ -112,4 +136,6 @@ yarn() { unset -f yarn; load-nvm; yarn "$@"; }
 ################################################################################
 ################################################################################
 # Private or system-specific environment variables
 # Private or system-specific environment variables
 ################################################################################
 ################################################################################
-source $ZDOTDIR/.zshenv.private
+if [ -f $ZDOTDIR/.zshenv.private ]; then
+    source $ZDOTDIR/.zshenv.private
+fi

+ 21 - 21
.config/zsh/.zshrc

@@ -1,35 +1,35 @@
-################################################################################
-# ZSH Configuration
-#
-# Note: in order for files in ~/.config/ to be picked up, be sure to set the
-# global XDG_* and ZDOTDIR paths. On macOS, these is set at /etc/zshenv, and
-# look something like the following block:
-#
-# export XDG_CONFIG_HOME=$HOME/.config
-# export XDG_CACHE_HOME=$HOME/.cache
-# export XDG_DATA_HOME=$HOME/.local/share
-# export XDG_STATE_HOME=$HOME/.local/state
-# export XDG_RUNTIME_DIR=$HOME/.run
-# export XDG_DATA_DIRS=/usr/local/share:/usr/share
-# export XDG_CONFIG_DIRS=/etc/xdg
-# export ZDOTDIR=$XDG_CONFIG_HOME/zsh
-#
-################################################################################
-
 ################################################################################
 ################################################################################
 # Basic configuration
 # Basic configuration
 ################################################################################
 ################################################################################
 
 
+setopt BEEP
 export TERM=alacritty
 export TERM=alacritty
 export LANG=en_US.UTF-8
 export LANG=en_US.UTF-8
 
 
-export HISTSIZE=50000
-export SAVEHIST=50000
+# Disable the log builtin, so we don't conflict with /usr/bin/log
+disable log
+
+# Correctly display UTF-8 with combining characters.
+if [[ "$(locale LC_CTYPE)" == "UTF-8" ]]; then
+    setopt COMBINING_CHARS
+fi
+
+################################################################################
+# History
+################################################################################
+
+HISTFILE=${ZDOTDIR}/.zsh_history
+HISTSIZE=2147483647
+SAVEHIST=$HISTSIZE
 export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
 export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
-setopt INC_APPEND_HISTORY
+setopt HIST_EXPIRE_DUPS_FIRST
 setopt HIST_IGNORE_ALL_DUPS
 setopt HIST_IGNORE_ALL_DUPS
+setopt HIST_IGNORE_DUPS
 setopt HIST_IGNORE_SPACE
 setopt HIST_IGNORE_SPACE
 setopt HIST_REDUCE_BLANKS
 setopt HIST_REDUCE_BLANKS
+setopt HIST_VERIFY
+setopt INC_APPEND_HISTORY
+setopt SHARE_HISTORY
 
 
 ################################################################################
 ################################################################################
 # Prompt
 # Prompt