From 4ef9c81b95c4c7ce4563aaea5400769d15831ee8 Mon Sep 17 00:00:00 2001 From: Vladislav Doster Date: Mon, 20 Mar 2023 02:57:44 -0500 Subject: [PATCH] fix: misc. zsh rc.d changes Signed-off-by: Vladislav Doster --- zsh/.config/zsh/rc.d/01-env.zsh | 39 ++++ zsh/.config/zsh/rc.d/01-hist.zsh | 40 ---- zsh/.config/zsh/rc.d/02-dirs.zsh | 6 +- zsh/.config/zsh/rc.d/03-zinit.zsh | 45 ++--- zsh/.config/zsh/rc.d/04-completion.zsh | 186 ++++++++++++++++++ zsh/.config/zsh/rc.d/04-env.zsh | 108 ---------- zsh/.config/zsh/rc.d/05-opt.zsh | 50 +++++ zsh/.config/zsh/rc.d/05-opts.zsh | 20 -- .../rc.d/{06-commands.zsh => 06-alias.zsh} | 18 +- zsh/.config/zsh/rc.d/07-widget.zsh | 6 +- 10 files changed, 306 insertions(+), 212 deletions(-) create mode 100755 zsh/.config/zsh/rc.d/01-env.zsh delete mode 100755 zsh/.config/zsh/rc.d/01-hist.zsh create mode 100755 zsh/.config/zsh/rc.d/04-completion.zsh delete mode 100755 zsh/.config/zsh/rc.d/04-env.zsh create mode 100755 zsh/.config/zsh/rc.d/05-opt.zsh delete mode 100755 zsh/.config/zsh/rc.d/05-opts.zsh rename zsh/.config/zsh/rc.d/{06-commands.zsh => 06-alias.zsh} (93%) diff --git a/zsh/.config/zsh/rc.d/01-env.zsh b/zsh/.config/zsh/rc.d/01-env.zsh new file mode 100755 index 00000000..47312fd7 --- /dev/null +++ b/zsh/.config/zsh/rc.d/01-env.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +setopt extendedglob +# +# Environment variables +# +(( ${+TERM} )) || export TERM="xterm-256color"; COLORTERM="truecolor" +(( ${+USER} )) || export USER="${USERNAME}" +(( ${+XDG_CACHE_HOME} )) || export XDG_CACHE_HOME="${HOME}/.cache" +(( ${+XDG_CONFIG_HOME} )) || export XDG_CONFIG_HOME="${HOME}/.config" +(( ${+XDG_DATA_HOME} )) || export XDG_DATA_HOME="${HOME}/.local/share" +# configuration directories +export \ + DOTFILES="${XDG_CONFIG_HOME}/dotfiles" GIT_CONFIG="${XDG_CONFIG_HOME}/git/config" \ + PIP_CONFIG="${XDG_CONFIG_HOME}/pip" PYTHONSTARTUP="${XDG_CONFIG_HOME}/python/init-repl.py" \ + VIMDOTDIR="${XDG_CONFIG_HOME}/vim" ZDOTDIR="${XDG_CONFIG_HOME}/zsh" +# program options +export \ + COMPOSE_DOCKER_CLI_BUILD=1 CORRECT_IGNORE="*zinit[-]*" \ + DISABLE_MAGIC_FUNCTIONS=1 DOCKER_BUILDKIT=1 \ + HOMEBREW_NO_{ENV_HINTS,INSTALL_CLEANUP}=1 \ + SHELL_SESSIONS_DISABLE=1 +export L{ANG{,UAGE},C_ALL}='en_US.UTF-8' +# $PATH and $path (and also $FPATH and $fpath, etc.) are "tied" to each other. +# Modifying one will also modify the other. +# Note that each value in an array is expanded separately. Thus, we can use ~ +# for $HOME in each $path entry. +_comp_dumpfile="$ZDOTDIR/zcompdump" + +typeset -gU fpath FPATH path PATH +path=( /opt/homebrew/bin(N) /usr/local/homebrew/bin(N) /home/linuxbrew/.linuxbrew/bin(N) $path ) +eval "$(brew shellenv)" +fpath=( ~/.config/zsh/{func,comple}tions(N) ~/.config/zsh/completions(N) $fpath ) +autoload -Uz ~/.config/zsh/functions/**/* +if command -v brew > /dev/null; then + eval "$(brew shellenv)" + path+=( ${HOMEBREW_PREFIX}/(s|)bin $path ) + fpath+=( $HOMEBREW_PREFIX/share/zsh/site-functions(N) $fpath ) +fi +path=( ~/.local/bin(N) ~/.local/bin/python/bin(N) $path ) diff --git a/zsh/.config/zsh/rc.d/01-hist.zsh b/zsh/.config/zsh/rc.d/01-hist.zsh deleted file mode 100755 index 799bc1e4..00000000 --- a/zsh/.config/zsh/rc.d/01-hist.zsh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env zsh -## -# History settings -# -# Always set these first, so history is preserved, no matter what happens. -# -# Enable additional glob operators. (Globbing = pattern matching) -# https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation -setopt EXTENDED_GLOB -# Tell zsh where to store history. -# $VENDOR and $OSTYPE let us check what kind of machine we're on. -if [[ $VENDOR == apple ]]; then - # On macOS, store it in iCloud, so it syncs across multiple Macs. - HISTFILE=~/Library/Mobile\ Documents/com\~apple\~CloudDocs/zsh_history - # Sometimes (probably due to concurrency issues), when the histfile is kept in - # iCloud, it is empty when Zsh starts up. However, there should always be a - # backup file we can copy. - # Move the largest "$HISTFILE " file to $HISTFILE. - # \ escapes/quotes the space behind it. - # (O): Sort descending. - # (OL): Sort by size, descending. - local -a files=( $HISTFILE(|\ <->)(OL) ) - [[ -r $files[1] ]] && - mv $files[1] $HISTFILE -else - # := assigns the variable and then substitutes the expression with its value. - HISTFILE=${XDG_DATA_HOME:=~/.local/share}/zsh/history -fi -# Just in case: If the parent directory doesn't exist, create it. -# [[ -d $HISTFILE(:h) ]] || mkdir -p $HISTFILE(:h) -# Max number of entries to keep in history file. -SAVEHIST=$(( 100 * 1000 )) # Use multiplication for readability. -# Max number of history entries to keep in memory. -HISTSIZE=$(( 1.2 * SAVEHIST )) # Zsh recommended value -# Use modern file-locking mechanisms, for better safety & performance. -setopt HIST_FCNTL_LOCK -# Keep only the most recent copy of each duplicate entry in history. -setopt HIST_IGNORE_ALL_DUPS -# Auto-sync history between concurrent sessions. -setopt SHARE_HISTORY diff --git a/zsh/.config/zsh/rc.d/02-dirs.zsh b/zsh/.config/zsh/rc.d/02-dirs.zsh index 3125405e..6809fe1e 100755 --- a/zsh/.config/zsh/rc.d/02-dirs.zsh +++ b/zsh/.config/zsh/rc.d/02-dirs.zsh @@ -1,7 +1,7 @@ #!/usr/bin/env zsh -# +## # Named directories -# -# Set these early, because it affects how dirs are displayed and printed. +## +# set these early, because it affects how dirs are displayed and printed. hash -d zsh=$ZDOTDIR hash -d code=$CODEDIR diff --git a/zsh/.config/zsh/rc.d/03-zinit.zsh b/zsh/.config/zsh/rc.d/03-zinit.zsh index 59d932f6..96930b00 100755 --- a/zsh/.config/zsh/rc.d/03-zinit.zsh +++ b/zsh/.config/zsh/rc.d/03-zinit.zsh @@ -8,7 +8,7 @@ typeset -gAH ZI=(HOME_DIR $HOME/.local/share/zinit) ZI+=( BIN_DIR "$ZI[HOME_DIR]/zinit.git" COMPLETIONS_DIR "$ZI[HOME_DIR]/completions" OPTIMIZE_OUT_OF_DISK_ACCESSES "1" - PLUGINS_DIR "$ZI[HOME_DIR]/plugins" SNIPPETS_DIR "$ZI[HOME_DIR]/snippets" ZCOMPDUMP_PATH "${ZDOTDIR:-$HOME/.config/zsh}/.zcompdump" + PLUGINS_DIR "$ZI[HOME_DIR]/plugins" SNIPPETS_DIR "$ZI[HOME_DIR]/snippets" ZCOMPDUMP_PATH "${ZDOTDIR:-$HOME/.config/zsh}/zcompdump" ZPFX "$ZI[HOME_DIR]/polaris" SRC 'zdharma-continuum' BRANCH 'main' ) ZSH_CACHE_DIR=$ZINIT[ZCOMPDUMP_PATH] @@ -36,18 +36,18 @@ else fi #=== OH-MY-ZSH & PREZTO PLUGINS ======================= zi is-snippet nocompletions light-mode compile light-mode for \ - {PZTM::environment,OMZL::{compfix,git,key-bindings,completion}.zsh} + {PZTM::environment,OMZP::gnu-utils,OMZL::{compfix,git,key-bindings,completion}.zsh} # zi as'completion' for OMZP::{'golang/_golang','pip/_pip'} # #=== COMPLETIONS ====================================== -local GH_RAW_URL='https://raw.githubusercontent.com' -znippet() { zi for as'completion' has"${1}" depth'1' light-mode nocompile id-as"${1}-completion/_${1}" is-snippet "${GH_RAW_URL}/${2}/_${1}"; } -znippet 'exa' 'ogham/exa/master/completions/zsh' +# local GH_RAW_URL='https://raw.githubusercontent.com' +# znippet() { zi for as'completion' has"${1}" depth'1' light-mode nocompile id-as"${1}-completion/_${1}" is-snippet "${GH_RAW_URL}/${2}/_${1}"; } +# znippet 'exa' 'ogham/exa/master/completions/zsh' # # znippet 'fd' 'sharkdp/fd/master/contrib/completion' -znippet 'brew' 'Homebrew/brew/master/completions/zsh' -znippet 'docker' 'docker/cli/master/contrib/completion/zsh' -zi as'completion' light-mode nocompile is-snippet for \ - "${GH_RAW_URL}/git/git/master/contrib/completion/git-completion.zsh" \ - "${GH_RAW_URL}/Homebrew/homebrew-services/master/completions/zsh/_brew_services" +# znippet 'brew' 'Homebrew/brew/master/completions/zsh' +# znippet 'docker' 'docker/cli/master/contrib/completion/zsh' +# zi as'completion' light-mode nocompile is-snippet for \ +# "${GH_RAW_URL}/git/git/master/contrib/completion/git-completion.zsh" \ +# "${GH_RAW_URL}/Homebrew/homebrew-services/master/completions/zsh/_brew_services" #=== PROMPT =========================================== eval "MODE_CURSOR_"{'SEARCH="#ff00ff blinking underline"','VICMD="green block"','VIINS="#ffff00 bar"'}";" zinit for compile'(pure|async).zsh' multisrc'(pure|async).zsh' atinit" @@ -60,7 +60,7 @@ zstyle ':prompt:pure:path' color 'cyan' zstyle ':prompt:pure:prompt:success' color 'green'" load \ @sindresorhus/pure #=== ANNEXES ========================================== -zi light-mode for @${ZI[SRC]}/zinit-annex-{binary-symlink,default-ice,linkman,patch-dl,submods,bin-gem-node} +zi light-mode compile nocompletions for @${ZI[SRC]}/zinit-annex-{binary-symlink,default-ice,linkman,patch-dl,submods,bin-gem-node} #=== GITHUB BINARIES ================================== # zinit wait lucid from"gh-r" as"command" for sbin"**/bin/nvim" ver"nightly" neovim/neovim zi default-ice --quiet from"gh-r" light-mode lbin'!' nocompile @@ -76,7 +76,7 @@ zi lman lbin'!' light-mode for \ lbin'!**/exa -> exa' atinit"alias l='exa -blF'; alias la='exa -abghilmu'; alias ll='exa -al'; alias ls='exa --git --group-directories-first'" \ @ogham/exa zi default-ice --clear --quiet -zi default-ice --quiet light-mode depth'1' +zi default-ice --quiet light-mode for i (v vi vim); do alias $i="nvim"; done # alias l='exa -blF'; alias la='exa -abghilmu'; alias ll='exa -al'; alias ls='exa --git --group-directories-first' #=== UNIT TESTING ===================================== @@ -84,6 +84,7 @@ for i (v vi vim); do alias $i="nvim"; done zi ice nocompile mv'*completion -> _revolver' lbin'!'; zi light molovo/revolver zi lucid wait'!' light-mode completions for \ null make'PREFIX=${ZI[PLUGINS_DIR]}/zshelldoc --always-make' lbin'!build/zsd*' \ + ver'style/logging' \ @zdharma-continuum/zshelldoc \ atinit'bindkey -M vicmd "^v" edit-command-line' \ @softmoth/zsh-vim-mode \ @@ -96,18 +97,14 @@ zi lucid wait'!' light-mode completions for \ # zsh-users/zsh-completions \ # atload"!_zsh_autosuggest_start" \ # zsh-users/zsh-autosuggestions -zi lucid wait light-mode depth'1' for \ - svn submods'zsh-users/zsh-history-substring-search -> external' \ +zi lucid wait light-mode for \ + svn submods'zsh-users/zsh-history-substring-search -> external' \ OMZP::history-substring-search \ - atpull'zinit creinstall -q .' blockf null \ + atpull'zinit creinstall -q .' blockf \ zsh-users/zsh-completions \ - svn submods'zsh-users/zsh-completions -> external' \ - PZTM::completion \ - atload'!_zsh_autosuggest_start' atinit'bindkey "^_" autosuggest-execute;bindkey "^ " autosuggest-accept;' \ - zsh-users/zsh-autosuggestions -zi ice lucid wait'0c' depth'1' atclone'(){local f;cd -q →*;for f (*~*.zwc){zcompile -Uz -- ${f}};}' atpull'%atclone' compile'.*fast*~*.zwc' -zi light "${ZI[FORK]:-${ZI[SRC]}}"/fast-syntax-highlighting -autoload select-word-style -select-word-style normal -zstyle ':zle:*' word-chars '*?[]~;!#$%^(){}<>' + atload'!_zsh_autosuggest_start' atinit'bindkey "^_" autosuggest-execute;bindkey "^ " autosuggest-accept;' \ + zsh-users/zsh-autosuggestions \ + atclone'(){local f;cd -q →*;for f (*~*.zwc){zcompile -Uz -- ${f}};}' atpull'%atclone' compile'.*fast*~*.zwc' \ + "${ZI[FORK]:-${ZI[SRC]}}"/fast-syntax-highlighting + # vim: set expandtab filetype=zsh shiftwidth=2 softtabstop=2 tabstop=2: diff --git a/zsh/.config/zsh/rc.d/04-completion.zsh b/zsh/.config/zsh/rc.d/04-completion.zsh new file mode 100755 index 00000000..fbfb25fc --- /dev/null +++ b/zsh/.config/zsh/rc.d/04-completion.zsh @@ -0,0 +1,186 @@ +# +# Sets completion options. +# +# Authors: +# Robby Russell +# Sorin Ionescu +# + +# Return if requirements are not found. +if [[ $TERM == 'dumb' ]]; then + return 1 +fi + +# Add zsh-completions to $fpath. +fpath=(${0:h}/external/src $fpath) + +# Add completion for keg-only brewed curl on macOS when available. +if (( $+commands[brew] )); then + brew_prefix=${HOMEBREW_PREFIX:-${HOMEBREW_REPOSITORY:-$commands[brew]:A:h:h}} + # $HOMEBREW_PREFIX defaults to $HOMEBREW_REPOSITORY but is explicitly set to + # /usr/local when $HOMEBREW_REPOSITORY is /usr/local/Homebrew. + # https://github.com/Homebrew/brew/blob/2a850e02d8f2dedcad7164c2f4b95d340a7200bb/bin/brew#L66-L69 + [[ $brew_prefix == '/usr/local/Homebrew' ]] && brew_prefix=$brew_prefix:h + fpath=($brew_prefix/opt/curl/share/zsh/site-functions(/N) $fpath) + unset brew_prefix +fi + +# +# Options +# + +setopt COMPLETE_IN_WORD # Complete from both ends of a word. +setopt ALWAYS_TO_END # Move cursor to the end of a completed word. +setopt PATH_DIRS # Perform path search even on command names with slashes. +setopt AUTO_MENU # Show completion menu on a successive tab press. +setopt AUTO_LIST # Automatically list choices on ambiguous completion. +setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash. +setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit. +unsetopt MENU_COMPLETE # Do not autoselect the first completion entry. +unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor. + +# +# Variables +# + +# Standard style used by default for 'list-colors' +LS_COLORS=${LS_COLORS:-'di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'} + +# +# Initialization +# + +# Load and initialize the completion system ignoring insecure directories with a +# cache time of 20 hours, so it should almost always regenerate the first time a +# shell is opened each day. +autoload -Uz compinit +_comp_path="${XDG_CONFIG_HOME:-$HOME/.config}/zsh/zcompdump" +# #q expands globs in conditional expressions +if [[ $_comp_path(#qNmh-20) ]]; then + # -C (skip function check) implies -i (skip security check). + compinit -C -d "$_comp_path" +else + mkdir -p "$_comp_path:h" + compinit -i -d "$_comp_path" + # Keep $_comp_path younger than cache time even if it isn't regenerated. + touch "$_comp_path" +fi +unset _comp_path + +# +# Styles +# + +# Defaults. +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:default' list-prompt '%S%M matches%s' + +# Use caching to make completion for commands such as dpkg and apt usable. +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path "${XDG_CONFIG_HOME:-$HOME/.config}/zsh/zcompcache" + +zstyle ':completion:*' rehash true +# Case-insensitive (all), partial-word, and then substring completion. +# zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +# setopt CASE_GLOB +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +unsetopt CASE_GLOB + +# Group matches and describe. +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*:matches' group 'yes' +zstyle ':completion:*:options' description 'yes' +zstyle ':completion:*:options' auto-description '%d' +zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' +zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' +zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' +zstyle ':completion:*' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' verbose yes + +# Fuzzy match mistyped completions. +zstyle ':completion:*' completer _complete _match _approximate +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 1 numeric + +# Increase the number of errors based on the length of the typed word. But make +# sure to cap (at 7) the max-errors to avoid hanging. +zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)' + +# Don't complete unavailable commands. +zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))' + +# Array completion element sorting. +zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters + +# Directories +zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories +zstyle ':completion:*:*:cd:*:directory-stack' menu yes select +zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' +zstyle ':completion:*' squeeze-slashes true + +# History +zstyle ':completion:*:history-words' stop yes +zstyle ':completion:*:history-words' remove-all-dups yes +zstyle ':completion:*:history-words' list false +zstyle ':completion:*:history-words' menu yes + +# Environment Variables +zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-} + +# Populate hostname completion. But allow ignoring custom entries from static +# */etc/hosts* which might be uninteresting. +zstyle -e ':completion:*:hosts' hosts 'reply=( + ${=${=${=${${(f)"$(cat {/etc/ssh/ssh_,~/.ssh/}known_hosts(|2)(N) 2> /dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } + ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2> /dev/null))"}%%(\#${_etc_host_ignores:+|${(j:|:)~_etc_host_ignores}})*} + ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2> /dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} +)' + +# Don't complete uninteresting users... +zstyle ':completion:*:*:*:users' ignored-patterns \ + adm amanda apache avahi beaglidx bin cacti canna clamav daemon \ + dbus distcache dovecot fax ftp games gdm gkrellmd gopher \ + hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \ + mailman mailnull mldonkey mysql nagios \ + named netdump news nfsnobody nobody nscd ntp nut nx openvpn \ + operator pcap postfix postgres privoxy pulse pvm quagga radvd \ + rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*' + +# ... unless we really want to. +zstyle '*' single-ignored show + +# Ignore multiple entries. +zstyle ':completion:*:(rm|kill|diff):*' ignore-line other +zstyle ':completion:*:rm:*' file-patterns '*:all-files' + +# Kill +zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w' +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01' +zstyle ':completion:*:*:kill:*' menu yes select +zstyle ':completion:*:*:kill:*' force-list always +zstyle ':completion:*:*:kill:*' insert-ids single + +# Man +zstyle ':completion:*:manuals' separate-sections true +zstyle ':completion:*:manuals.(^1*)' insert-sections true + +# Media Players +zstyle ':completion:*:*:mpg123:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories' +zstyle ':completion:*:*:mpg321:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories' +zstyle ':completion:*:*:ogg123:*' file-patterns '*.(ogg|OGG|flac):ogg\ files *(-/):directories' +zstyle ':completion:*:*:mocp:*' file-patterns '*.(wav|WAV|mp3|MP3|ogg|OGG|flac):ogg\ files *(-/):directories' + +# Mutt +if [[ -s "$HOME/.mutt/aliases" ]]; then + zstyle ':completion:*:*:mutt:*' menu yes select + zstyle ':completion:*:mutt:*' users ${${${(f)"$(<"$HOME/.mutt/aliases")"}#alias[[:space:]]}%%[[:space:]]*} +fi + +# SSH/SCP/RSYNC +zstyle ':completion:*:(ssh|scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr +zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' diff --git a/zsh/.config/zsh/rc.d/04-env.zsh b/zsh/.config/zsh/rc.d/04-env.zsh deleted file mode 100755 index 85efbfde..00000000 --- a/zsh/.config/zsh/rc.d/04-env.zsh +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env zsh -setopt extendedglob - -## -# Environment variables -# -# -U ensures each entry in these is unique (that is, discards duplicates). -# typeset -agU fpath manpath path -# -# fpath+=( ~zsh/(func|comple)tions $fpath ) -# local fn -# # for fn in ${0:A:h}/functions/*; do -# for fn in ~zsh/functions/*; do -# # (( $+functions[${fn:t}] )) && unfunction ${fn:t} -# # only autoload extensionless files -# [[ -z "${fn:e}" ]] && autoload -Uz "${fn}" -# done -# typeset -U fpath path -# fpath=( ~/.config/zsh/functions ~/.config/zsh/completions "${fpath[@]}" ) -# autoload -Uz $fpath[1]/*(.:t) -# -# autoload -Uz zrecompile -# for ((i=1; i <= $#fpath; ++i)); do -# dir=$fpath[i] -# zwc=${dir:t}.zwc -# if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then -# continue -# fi -# files=($dir/*(N-.)) -# if [[ -w $dir:h && -n $files ]]; then -# files=(${${(M)files%/*/*}#/}) -# if ( cd $dir:h && -# zrecompile -p -U -z $zwc $files ); then -# fpath[i]=$fpath[i].zwc -# fi -# fi -# done -# export -UT INFOPATH infopath # -T creates a "tied" pair; see below. -(( ${+TERM} )) || export TERM="xterm-256color"; COLORTERM="truecolor" -(( ${+USER} )) || export USER="${USERNAME}" -(( ${+XDG_CACHE_HOME} )) || export XDG_CACHE_HOME="${HOME}/.cache" -(( ${+XDG_CONFIG_HOME} )) || export XDG_CONFIG_HOME="${HOME}/.config" -(( ${+XDG_DATA_HOME} )) || export XDG_DATA_HOME="${HOME}/.local/share" -# configuration directories -export \ - DOTFILES="${XDG_CONFIG_HOME}/dotfiles" GIT_CONFIG="${XDG_CONFIG_HOME}/git/config" \ - PIP_CONFIG="${XDG_CONFIG_HOME}/pip" PYTHONSTARTUP="${XDG_CONFIG_HOME}/python/init-repl.py" \ - VIMDOTDIR="${XDG_CONFIG_HOME}/vim" ZDOTDIR="${XDG_CONFIG_HOME}/zsh" -# program options -export \ - COMPOSE_DOCKER_CLI_BUILD=1 CORRECT_IGNORE="*zinit[-]*" \ - DISABLE_MAGIC_FUNCTIONS=1 DOCKER_BUILDKIT=1 \ - HOMEBREW_NO_{ENV_HINTS,INSTALL_CLEANUP}=1 \ - SHELL_SESSIONS_DISABLE=1 -export L{ANG{,UAGE},C_ALL}='en_US.UTF-8' -# $PATH and $path (and also $FPATH and $fpath, etc.) are "tied" to each other. -# Modifying one will also modify the other. -# Note that each value in an array is expanded separately. Thus, we can use ~ -# for $HOME in each $path entry. -typeset -gU fpath FPATH path PATH -path=( - ~/.local/bin(N) - ~/.local/bin/python/bin(N) - /opt/homebrew/bin(N) - /usr/local/homebrew/bin(N) - /home/linuxbrew/.linuxbrew/bin(N) - $path -) -# Add your functions to your $fpath, so you can autoload them. -# fpath=( -# ~zsh/functions/*(N) -# $fpath -# ) -# -# -# 0=${(%):-%x} -# print "location ${0:A:h}" -# fpath=( "${0:A:h}" $fpath ) -# local fn -# # for fn in ${0:A:h}/functions/*; do -# for fn in ${0:A:h}/*; do -# (( $+functions[${fn:t}] )) && unfunction ${fn:t} -# # only autoload extensionless files -# [[ -z "${fn:e}" ]] && autoload -Uz "${fn}" -# done -# print -l $fpath -eval "$(brew shellenv)" -fpath=( - ~/.config/zsh/{func,comple}tions(N) - ~/.config/zsh/completions(N) - $fpath -) -autoload -Uz ~/.config/zsh/functions/**/* -if command -v brew > /dev/null; then - eval "$(brew shellenv)" - path+=( - ${HOMEBREW_PREFIX}/(s|)bin - $path - ) - # Add dirs containing completion functions to your $fpath and they will be - # picked up automatically when the completion system is initialized. - # Here, we add it to the end of $fpath, so that we use brew's completions - # only for those commands that zsh doesn't already know how to complete. - fpath+=( - $HOMEBREW_PREFIX/share/zsh/site-functions(N) - $fpath - ) -fi diff --git a/zsh/.config/zsh/rc.d/05-opt.zsh b/zsh/.config/zsh/rc.d/05-opt.zsh new file mode 100755 index 00000000..b705c1f1 --- /dev/null +++ b/zsh/.config/zsh/rc.d/05-opt.zsh @@ -0,0 +1,50 @@ +# vim:ft=zsh +#!/usr/bin/env zsh +# Smart URLs +autoload -Uz url-quote-magic +zle -N self-insert url-quote-magic +# General +setopt brace_ccl # Allow brace character class list expansion. +setopt combining_chars # Combine zero-length punctuation characters (accents) with the base character. +setopt rc_quotes # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. +setopt no_mail_warning # Don't print a warning message if a mail file has been accessed. +setopt no_sh_word_split # Don't split value by words -- only on demand by http://zsh.sourceforge.net/FAQ/zshfaq03.html +### history +# USAGE: +# * zle keymap 'set-local-history' to toggle exclusive history movement +# * $ fc -RI $ NICE! manually import history from other terminals (only when you need it) +setopt no_share_history # Disable shared history between terminals / sessions (auto-importing) +setopt no_inc_append_history # Write to the history file immediately, not when the shell exits. +setopt inc_append_history_time # Write only after when command finishes (to have proper duration time) +setopt extended_history # Write the history file in the ':start:elapsed;command' format. +setopt bang_hist # Treat the '!' character specially during expansion. +setopt hist_expire_dups_first # Expire a duplicate event first when trimming history. +setopt hist_ignore_dups # Do not record an event that was just recorded again. +setopt hist_ignore_all_dups # Delete an old recorded event if a new event is a duplicate. +setopt hist_find_no_dups # Do not display a previously found event. +setopt hist_ignore_space # Do not record an event starting with a space. +setopt hist_save_no_dups # Do not write a duplicate event to the history file. +setopt hist_verify # Do not execute immediately upon history expansion. +setopt hist_beep # Beep when accessing non-existent history. +# DFL: HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" +HISTFILE=${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history +# BET:(audit,transient): prevent frequently changing file to pollute BTRFS snapshots +# HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/zsh/history +# # INFO: =20000cmds/year OR: use logrotate-esque way to store old history in archive +# # SRC: https://unix.stackexchange.com/questions/273861/unlimited-history-in-zsh +# HISTSIZE=1000000 # The maximum number of events to save in the internal history. +# SAVEHIST=1000000 # The maximum number of events to save in the history file. +# Jobs +# WARN: zsh you have running jobs +# If I exit again, my jobs are killed. But zsh accept some useful option to overide this : nohup nocheckjobs +setopt long_list_jobs # List jobs on suspend in the long format by default. +setopt auto_resume # Attempt to resume existing job before creating a new process. +setopt notify # Report status of background jobs immediately. +setopt no_bg_nice # Don't run all background jobs at a lower priority. +setopt no_hup # Don't kill jobs on shell exit. +setopt no_check_jobs # Don't report on jobs when shell exit. +setopt no_print_exit_value # Alert if something failed +{ # New options (may be unavailable) + setopt pipe_fail # Exit pipe with rightmost non-zero code +} 2>/dev/null +FPATH="${HOME}"/.config/zsh/completions:${FPATH} diff --git a/zsh/.config/zsh/rc.d/05-opts.zsh b/zsh/.config/zsh/rc.d/05-opts.zsh deleted file mode 100755 index 1cab8a06..00000000 --- a/zsh/.config/zsh/rc.d/05-opts.zsh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env zsh -## -# Shell options that don't fit in any other file. -# -# Set these after sourcing plugins, because those might set options, too. -# -# don't let > silently overwrite files. to overwrite, use >! instead. -setopt NO_CLOBBER -# treat comments pasted into the command line as comments, not code. -setopt INTERACTIVE_COMMENTS -# don't treat non-executable files in your $path as commands. this makes sure -# they don't show up as command completions. settinig this option can impact -# performance on older systems, but should not be a problem on modern ones. -setopt HASH_EXECUTABLES_ONLY -# enable ** and *** as shortcuts for **/* and ***/*, respectively. -# https://zsh.sourceforge.io/Doc/Release/Expansion.html#Recursive-Globbing -setopt GLOB_STAR_SHORT -# sort numbers numerically, not lexicographically. -setopt NUMERIC_GLOB_SORT -zstyle ':completion:*' rehash true diff --git a/zsh/.config/zsh/rc.d/06-commands.zsh b/zsh/.config/zsh/rc.d/06-alias.zsh similarity index 93% rename from zsh/.config/zsh/rc.d/06-commands.zsh rename to zsh/.config/zsh/rc.d/06-alias.zsh index cb1645a2..5cf26fc7 100755 --- a/zsh/.config/zsh/rc.d/06-commands.zsh +++ b/zsh/.config/zsh/rc.d/06-alias.zsh @@ -1,19 +1,9 @@ #!/usr/bin/env zsh ## # Commands, funtions and aliases -# # Always set aliases _last,_ so they don't get used in function definitions. -# -# This lets you change to any dir without having to type `cd`, that is, by just -# typing its name. Be warned, though: This can misfire if there exists an alias, -# function, builtin or command with the same name. -# In general, I would recommend you use only the following without `cd`: -# .. to go one dir up -# ~ to go to your home dir -# ~-2 to go to the 2nd mostly recently visited dir -# / to go to the root dir -setopt AUTO_CD -# Type '-' to return to your previous dir. +## +# type '-' to return to your previous dir. alias -- -='cd -q -' alias -- b='-' # '--' signifies the end of options. Otherwise, '-=...' would be interpreted as @@ -103,10 +93,10 @@ alias zireset='builtin cd ${HOME}; unset _comp{_{assocs,dumpfile,options,setup}, # │ NAVIGATION │ # +────────────+ typeset -A pairs=( - bin '~/.local/bin' + bin '~/.local/bin' .. '../' dl '~/Downloads' xch '~/.config' xdh '${XDG_DATA_HOME:-~/.local/share}' - zd '$ZDOTDIR' zfd '$ZDOTDIR/functions' + zdd '$ZDOTDIR' zfd '$ZDOTDIR/functions' ) # rr '$(git rev-parse --show-toplevel)' zs ' ' for k v in ${(kv)pairs[@]}; do diff --git a/zsh/.config/zsh/rc.d/07-widget.zsh b/zsh/.config/zsh/rc.d/07-widget.zsh index c7157f0b..170837fb 100755 --- a/zsh/.config/zsh/rc.d/07-widget.zsh +++ b/zsh/.config/zsh/rc.d/07-widget.zsh @@ -25,9 +25,9 @@ zle -N accept-line _accept-line-with-url # Bind +s to `git status` function _git-status { - zle .kill-whole-line - BUFFER="git status" - zle .accept-line + zle .kill-whole-line + BUFFER="git status" + zle .accept-line } zle -N _git-status && bindkey '\es' _git-status