Skip to content

Commit

Permalink
fix: misc. zsh rc.d changes
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
  • Loading branch information
vladdoster committed Mar 20, 2023
1 parent 0852de5 commit 4ef9c81
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 212 deletions.
39 changes: 39 additions & 0 deletions zsh/.config/zsh/rc.d/01-env.zsh
Original file line number Diff line number Diff line change
@@ -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 )
40 changes: 0 additions & 40 deletions zsh/.config/zsh/rc.d/01-hist.zsh

This file was deleted.

6 changes: 3 additions & 3 deletions zsh/.config/zsh/rc.d/02-dirs.zsh
Original file line number Diff line number Diff line change
@@ -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
45 changes: 21 additions & 24 deletions zsh/.config/zsh/rc.d/03-zinit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -76,14 +76,15 @@ 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 =====================================
# zinit as'program' atpull'./build.zsh' src'zunit' for @vladdoster/zunit
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 \
Expand All @@ -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:
186 changes: 186 additions & 0 deletions zsh/.config/zsh/rc.d/04-completion.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#
# Sets completion options.
#
# Authors:
# Robby Russell <robby@planetargon.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
#

# 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::*'
Loading

0 comments on commit 4ef9c81

Please sign in to comment.