🔧 Updates ZSH config

This commit is contained in:
Alicia Sykes 2022-03-13 22:43:08 +00:00
parent 77109d0e02
commit 777df4a04c
15 changed files with 3773 additions and 9 deletions

1674
zsh/.p10k.zsh Normal file

File diff suppressed because it is too large Load Diff

1794
zsh/.zcompdump Normal file

File diff suppressed because it is too large Load Diff

BIN
zsh/.zcompdump.zwc Normal file

Binary file not shown.

16
zsh/.zlogin Normal file
View File

@ -0,0 +1,16 @@
# ~/.zlogin
# Compile .zcompdump file, if modified, to increase startup speed
# Executed on startin the background, so won't afftect current session
# Credit @htr3n. More info: https://htr3n.github.io/2018/07/faster-zsh/
{
zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]];
then
zcompile "$zcompdump"
fi
} &!

5
zsh/.zlogout Normal file
View File

@ -0,0 +1,5 @@
# ~/.zlogin
clear
reset

35
zsh/.zshenv Normal file
View File

@ -0,0 +1,35 @@
# ~/.zshenv
# Core envionmental variables
# Set XDG directories
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_BIN_HOME="${HOME}/.local/bin"
export XDG_LIB_HOME="${HOME}/.local/lib"
export XDG_CACHE_HOME="${HOME}/.cache"
# Set default applications
export EDITOR="vim"
export TERMINAL="konsole"
export BROWSER="firefox"
export PAGER="less"
## Respect XDG directories
export ADOTDIR="${XDG_CACHE_HOME}/zsh/antigen"
# export ANTIGEN_LOG="${XDG_CACHE_HOME}/zsh/antigen"
export ANTIBODY_HOME=${XDG_DATA_HOME}/antibody
export CARGO_HOME="${XDG_DATA_HOME}/cargo"
export DOCKER_CONFIG="${XDG_CONFIG_HOME}/docker"
export KDEHOME="${XDG_CONFIG_HOME}/kde"
export LESSHISTFILE="-" # Disable less history.
export PASSWORD_STORE_DIR="${XDG_DATA_HOME}/pass"
export PIP_CONFIG_FILE="${XDG_CONFIG_HOME}/pip/pip.conf"
export PIP_LOG_FILE="${XDG_DATA_HOME}/pip/log"
export VIMINIT=":source $XDG_CONFIG_HOME/vim/vimrc"
export WGETRC="${XDG_CONFIG_HOME}/wget/wgetrc"
export XINITRC="${XDG_CONFIG_HOME}/X11/xinitrc"
export XSERVERRC="${XDG_CONFIG_HOME}/X11/xserverrc"
export ZDOTDIR="${XDG_CONFIG_HOME}/zsh"
export ZLIB="${ZDOTDIR}/lib"
# source $XDG_CONFIG_HOME/zsh/.zshrc

View File

@ -5,8 +5,18 @@ zsh_dir=${${ZDOTDIR}:-$HOME/.config/zsh}
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Import ZSH settings file
source ${zsh_dir}/zsh-config.zsh
# Configure ZSH stuff
source ${zsh_dir}/lib/history.zsh
source ${zsh_dir}/lib/colors.zsh
source ${zsh_dir}/lib/completion.zsh
source ${zsh_dir}/lib/term-title.zsh
# Import alias files
source ${zsh_dir}/aliases/git.zsh
source ${zsh_dir}/aliases/general.zsh
# Setup Antigen bundle manager
source ${zsh_dir}/helpers/setup-antigen.zsh
@ -14,14 +24,5 @@ source ${zsh_dir}/helpers/setup-antigen.zsh
# Then import Antigen plugins
source ${zsh_dir}/helpers/import-plugins.zsh
# Enable auto-completion
autoload -Uz compinit
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
compinit -i
else
compinit -C -i
fi
# Import P10k config for command prompt, run `p10k configure` or edit
[[ ! -f ${zsh_dir}/.p10k.zsh ]] || source ${zsh_dir}/.p10k.zsh

39
zsh/aliases/general.zsh Normal file
View File

@ -0,0 +1,39 @@
command_exists () {
hash "$1" 2> /dev/null
}
# Use exa package (if installed) for better ls
# if command_exists exa ; then
# alias ls='exa'
# alias la='exa -a --icons'
# alias tree='f() { exa -a --tree -L=${1:-2} --icons };f'
# alias recent='exa -lahr --color-scale --icons --git --git-ignore -s=modified'
# else
# alias la='ls -a'
# fi
# Shorter ls
alias l='ls' # List files, will use exa if availible
alias ll='ls -laFh' # List all files, with details, type indicators and headings
alias dud='du -d 1 -h' # List sizes of files within directory
alias duf='du -sh *' # List total size of current directory
alias ff='find . -type f -name' # Find a file by name within current directory
(( $+commands[fd] )) || alias fd='find . -type d -name' # Find direcroy by name
alias hist='history'
alias histsearch='fc -El 0 | grep' # Searchses for a word in terminal history
# Command line head / tail shortcuts
alias -g H='| head' # Pipes output to head (the first part of a file)
alias -g T='| tail' # Pipes output to tail (the last part of a file)
alias -g G='| grep' # Pipes output to grep to search for some word
alias -g L="| less" # Pipes output to less, useful for paging
alias -g M="| most" # Pipes output to more, useful for paging
alias -g LL="2>&1 | less" # Writes stderr to stdout and passes it to less
alias -g CA="2>&1 | cat -A" # Writes stderr to stdout and passes it to cat
alias -g NE="2> /dev/null" # Silences stderr
alias -g NUL="> /dev/null 2>&1" # Silences both stdout and stderr
alias -g P="2>&1| pygmentize -l pytb" # Writes stderr to stdout, and passes to pygmentize

View File

@ -0,0 +1,27 @@
# Syntax highlighting for commands
antigen bundle zsh-users/zsh-syntax-highlighting
# Make and cd into nested directories
antigen bundle caarlos0/zsh-mkc
# Extra zsh completions
antigen bundle zsh-users/zsh-completions
# Auto suggestions from history
antigen bundle zsh-users/zsh-autosuggestions
# Pretty directory listings with git support
antigen bundle supercrabtree/k
# Quickly jump into fequently used directories
# antigen bundle autojump
# Syntax highlighting for cat
antigen bundle colorize
# Tons of helper functions for git repos
antigen bundle unixorn/git-extra-commands
# Tell antigen that you're done
antigen apply

View File

@ -0,0 +1,22 @@
zsh_dir=${XDG_CONFIG_HOME:-$HOME/.config}/zsh
antigen_dir=${ADOTDIR:-$XDG_DATA_HOME/zsh/antigen}
antigen_bin="${ADOTDIR}/antigen.zsh"
# Import angigen if present, or prompt to install if missing
if [[ -f $antigen_bin ]]; then
source $antigen_bin
else
if read -q "choice?Would you like to install Antigen now? (y/N)"; then
echo
mkdir -p $antigen_dir
curl -L git.io/antigen > $antigen_bin
source $antigen_bin
fi
fi
# Set the ZSH prompt
antigen theme romkatv/powerlevel10k

20
zsh/lib/colors.zsh Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env zsh
# Enable dircolors.
if type -p dircolors &>/dev/null; then
# Enable custom colors if it exists.
[ -e "${XDG_CONFIG_HOME}/dircolors" ] && \
eval "$(dircolors -b "${XDG_CONFIG_HOME}/dircolors")" || \
eval "$(dircolors -b)"
fi
# Colorize 'ls' command. Based on Oh My Zsh;
ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' }
alias vdir="vdir --color=auto" # Colorize 'vdir' command.
alias grep="grep --color=auto -i" # Colorize 'grep' command and ignore case.
alias fgrep="grep --color=auto -i" # Colorize 'fgrep' command and ignore case.
alias egrep="grep --color=auto -i" # Colorize 'egrep' command and ignore case.
alias diff="diff --color=auto" # Colorize 'diff' command.

78
zsh/lib/completion.zsh Normal file
View File

@ -0,0 +1,78 @@
#!/usr/bin/env zsh
# Configure completion cache.
zstyle ':completion::complete:*' use-cache yes # Enable cache for completions.
zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" # Configure completion cache path.
# Configure matches and grouping in completion menu.
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' # Enable case insensitive completion.
zstyle ':completion:*:*:*:*:*' menu select # Enable highlighting in menu.
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:options' description yes
zstyle ':completion:*:matches' group yes # Separate matches in menu into groups.
zstyle ':completion:*' group-name '' # Separate matches in menu into groups.
# Format group matches in completion menu.
#zstyle ':completion:*:descriptions' format '%F{yellow}-- %d --%f' # Comment when using fzf-tab plugin. For more information,
zstyle ':completion:*:descriptions' format '[%d]' # see https://github.com/Aloxaf/fzf-tab/issues/43.
zstyle ':completion:*:corrections' format '%F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:messages' format '%F{purple}-- %d --%f'
zstyle ':completion:*:warnings' format '%F{red}-- no matches found --%f'
# Configure completion of directories.
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} # Enable $LS_COLORS for directories in completion menu.
zstyle ':completion:*' special-dirs yes # Enable completion menu of ./ and ../ special directories.
# Configure completion of 'kill' command.
zstyle ':completion:*:*:*:*:processes' command 'ps -u $USER -o pid,user,command -w'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*' force-list always
zstyle ':completion:*:*:kill:*' insert-ids single
# Configure completion of 'man' command.
zstyle ':completion:*:man:*' menu yes select
zstyle ':completion:*:manuals' separate-sections yes
zstyle ':completion:*:manuals.*' insert-sections yes
################################################################################
# INITIALIZE & OPTIMIZE COMPLETION SYSTEM
################################################################################
#
# Performance tweaking of compinit based on information from the following
# sources.
# - https://carlosbecker.com/posts/speeding-up-zsh
# - https://gist.github.com/ctechols/ca1035271ad134841284
#
# On slow systems, checking the cached .zcompdump file to see if it must be
# regenerated adds a noticable delay to Zsh startup. The solution below
# restricts it to once a day.
#
# See below for infromation on the globbing used.
# '#q' : Explicit glob qualifier that makes globbing work within Zsh's [[ ]]
# construct.
# 'N' : Makes the glob pattern evaluate to nothing when it does not match,
# rather than throwing a globbing error.
# '.' : Match "regular files".
# 'm1' : Match files (or directories or whatever) that are older than 1 day.
# Autoload completion functions.
# -U : Mark the fucntion for autoloading and suppress alias expansion.
# -z : Use Zsh instead of Korn shell style functions.
autoload -Uz compinit
# Enable extended globbing.
setopt extendedglob
# Perform compinit only once a day.
if [[ -n ${ZDOTDIR:-$HOME}/.zcompdump(#qN.m1) ]]; then
compinit
echo "Initializing completions..."
else
# Skip compinit security check entirely.
compinit -c
fi
# Disable extended globbing so that ^ will behave as normal.
unsetopt extendedglob

18
zsh/lib/history.zsh Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env zsh
# Configure history file.
HISTFILE="${XDG_CACHE_HOME}/zsh/history"
HISTSIZE=50000
SAVEHIST=10000
# History command configuration.
setopt extended_history # Record timestamp of command in $HISTFILE.
setopt hist_expire_dups_first # Delete duplicates first when $HISTFILE size exceeds $HISTSIZE.
setopt hist_ignore_dups # Ignore duplicated commands in history list.
setopt hist_save_no_dups # Do not save duplicates in history file.
setopt hist_find_no_dups # Ignore duplicates when searching in history.
setopt hist_ignore_space # Ignore commands that start with a space.
setopt hist_reduce_blanks # Remove superfluous blanks from history items.
setopt hist_verify # Show command with history expansion to user before running it.
setopt inc_append_history # Add commands to $HISTFILE in order of execution.
setopt share_history # Share history between different instances of the shell.

21
zsh/lib/term-title.zsh Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env zsh
# Configures Xterm's title
# For more information, see https://wiki.archlinux.org/index.php/Zsh#xterm_title
autoload -Uz add-zsh-hook
xterm-title-precmd() {
print -Pn "\e]2;%n@%m %~\a"
[[ "${TERM}" == "screen"* ]] && print -Pn "\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-}\e\\"
}
xterm-title-preexec() {
print -Pn "\e]2;%n@%m %~ %# " && print -n "${(q)1}\a"
[[ "${TERM}" == "screen"* ]] && { print -Pn "\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-} %# " && print -n "${(q)1}\e\\"; }
}
if [[ "${TERM}" == (screen*|xterm*|rxvt*) ]]; then
add-zsh-hook -Uz precmd xterm-title-precmd
add-zsh-hook -Uz preexec xterm-title-preexec
fi

14
zsh/zsh-config.zsh Normal file
View File

@ -0,0 +1,14 @@
# Enable auto-completion
autoload -Uz compinit
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
compinit -i
else
compinit -C -i
fi
# Make zsh know about hosts already accessed by SSH
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' \
hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'