Skip to content

Instantly share code, notes, and snippets.

@santobollove
Last active May 5, 2021 15:05
Show Gist options
  • Save santobollove/38e8da22430a7e6463f0a62cebc193c2 to your computer and use it in GitHub Desktop.
Save santobollove/38e8da22430a7e6463f0a62cebc193c2 to your computer and use it in GitHub Desktop.
if [[ $- != *i* ]]; then
return
fi
# completion cache path setup
typeset -g comppath="$HOME/.cache"
typeset -g compfile="$comppath/.zcompdump"
if [[ -d "$comppath" ]]; then
[[ -w "$compfile" ]] || rm -rf "$compfile" >/dev/null 2>&1
else
mkdir -p "$comppath"
fi
# zsh internal stuff
SHELL=$(which zsh || echo '/usr/bin/zsh')
KEYTIMEOUT=1
SAVEHIST=100000
HISTSIZE=100000
HISTFILE="$HOME/.cache/.zsh_history"
alias ls='lsd'
alias l='ls -1'
alias la='ls -ld .?*'
alias ll='ls -l'
alias lla='ls -lAh'
alias lt='ls --tree'
alias grep='grep --color=auto'
alias G='| grep'
alias grub-update='sudo grub-mkconfig -o /boot/grub/grub.cfg'
alias mirror-update='sudo reflector --verbose --score 100 -l 50 -f 10 --sort rate --save /etc/pacman.d/mirrorlist'
# ls() # ls with preferred arguments
# {
# command ls --color=auto -F1 "$@"
# }
# cd() # cd and ls after
# {
# builtin cd "$@" && command ls --color=auto -F
# }
src() # recompile completion and reload zsh
{
autoload -U zrecompile
rm -rf "$compfile"*
compinit -u -d "$compfile"
zrecompile -p "$compfile"
exec zsh
}
wd() {
. /usr/share/wd/wd.sh
}
mcd() {
mkdir "$1"; cd "$1"
}
pyenv() {
. ~/Dark/Python-venv/"$1"/bin/activate;
}
xconv() {
ffmpeg -i "$1" -vcodec mpeg4 -vtag XVID -b 990k -bf 2 -g 300 -s 640x360 "$2".avi
}
eval "$(direnv hook zsh)"
export PATH=$PATH:$HOME/.cargo/bin:$HOME/.local/share/gem/ruby/3.0.0/bin:$HOME/.local/bin
# less/manpager colours
export MANWIDTH=120
export LESS='-R'
export LESSHISTFILE=-
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[32m'
export LESS_TERMCAP_mb=$'\e[31m'
export LESS_TERMCAP_md=$'\e[31m'
export LESS_TERMCAP_so=$'\e[47;30m'
export LESSPROMPT='?f%f .?ltLine %lt:?pt%pt\%:?btByte %bt:-...'
# completion
setopt CORRECT
setopt NO_NOMATCH
setopt LIST_PACKED
setopt ALWAYS_TO_END
setopt GLOB_COMPLETE
setopt COMPLETE_ALIASES
setopt COMPLETE_IN_WORD
# builtin command behaviour
setopt AUTO_CD
# job control
setopt AUTO_CONTINUE
setopt LONG_LIST_JOBS
# history control
setopt HIST_VERIFY
setopt SHARE_HISTORY
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
# misc
setopt EXTENDED_GLOB
setopt TRANSIENT_RPROMPT
setopt INTERACTIVE_COMMENTS
autoload -U compinit # completion
autoload -U terminfo # terminfo keys
zmodload -i zsh/complist # menu completion
autoload -U promptinit # prompt
# better history navigation, matching currently typed text
autoload -U up-line-or-beginning-search; zle -N up-line-or-beginning-search
autoload -U down-line-or-beginning-search; zle -N down-line-or-beginning-search
# set the terminal mode when entering or exiting zle, otherwise terminfo keys are not loaded
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
zle-line-init() { echoti smkx; }; zle -N zle-line-init
zle-line-finish() { echoti rmkx; }; zle -N zle-line-finish
fi
first_tab() # on first tab without any text it will list the current directory
{ # empty line tab lists
if [[ $#BUFFER == 0 ]]; then
BUFFER="cd " CURSOR=3
zle list-choices
BUFFER="" CURSOR=1
else
zle expand-or-complete
fi
}; zle -N first_tab
# exp_alias() # expand aliases to the left (if any) before inserting the key pressed
# { # expand aliases
# zle _expand_alias
# zle self-insert
# }; zle -N exp_alias
# bind keys not in terminfo
bindkey -- '^I' first_tab
# bindkey -- ' ' exp_alias
bindkey -- '^P' up-history
bindkey -- '^N' down-history
bindkey -- '^E' end-of-line
bindkey -- '^A' beginning-of-line
bindkey -- '^[^M' self-insert-unmeta # alt-enter to insert a newline/carriage return
bindkey -- '^K' up-line-or-beginning-search
bindkey -- '^J' down-line-or-beginning-search
# default shell behaviour using terminfo keys
[[ -n ${terminfo[kdch1]} ]] && bindkey -- "${terminfo[kdch1]}" delete-char # delete
[[ -n ${terminfo[kend]} ]] && bindkey -- "${terminfo[kend]}" end-of-line # end
[[ -n ${terminfo[kcuf1]} ]] && bindkey -- "${terminfo[kcuf1]}" forward-char # right arrow
[[ -n ${terminfo[kcub1]} ]] && bindkey -- "${terminfo[kcub1]}" backward-char # left arrow
[[ -n ${terminfo[kich1]} ]] && bindkey -- "${terminfo[kich1]}" overwrite-mode # insert
[[ -n ${terminfo[khome]} ]] && bindkey -- "${terminfo[khome]}" beginning-of-line # home
[[ -n ${terminfo[kbs]} ]] && bindkey -- "${terminfo[kbs]}" backward-delete-char # backspace
[[ -n ${terminfo[kcbt]} ]] && bindkey -- "${terminfo[kcbt]}" reverse-menu-complete # shift-tab
[[ -n ${terminfo[kcuu1]} ]] && bindkey -- "${terminfo[kcuu1]}" up-line-or-beginning-search # up arrow
[[ -n ${terminfo[kcud1]} ]] && bindkey -- "${terminfo[kcud1]}" down-line-or-beginning-search # down arrow
# correction
zstyle ':completion:*:correct:*' original true
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:approximate:*' max-errors 'reply=($(( ($#PREFIX + $#SUFFIX) / 3 )) numeric)'
# completion
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$comppath"
zstyle ':completion:*' rehash true
zstyle ':completion:*' verbose true
zstyle ':completion:*' insert-tab false
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:-command-:*:' verbose false
zstyle ':completion::complete:*' gain-privileges 1
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*' completer _complete _match _approximate _ignored
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
# labels and categories
zstyle ':completion:*' group-name ''
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' format ' %F{green}->%F{yellow} %d%f'
zstyle ':completion:*:messages' format ' %F{green}->%F{purple} %d%f'
zstyle ':completion:*:descriptions' format ' %F{green}->%F{yellow} %d%f'
zstyle ':completion:*:warnings' format ' %F{green}->%F{red} no matches%f'
zstyle ':completion:*:corrections' format ' %F{green}->%F{green} %d: %e%f'
# menu colours
eval "$(dircolors)"
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=36=0=01'
# command parameters
zstyle ':completion:*:functions' ignored-patterns '(prompt*|_*|*precmd*|*preexec*)'
zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
zstyle ':completion:*:(vim|nvim|vi|nano):*' ignored-patterns '*.(wav|mp3|flac|ogg|mp4|avi|mkv|iso|so|o|7z|zip|tar|gz|bz2|rar|deb|pkg|gzip|pdf|png|jpeg|jpg|gif)'
# hostnames and addresses
zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
zstyle ':completion:*:(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|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::*'
zstyle -e ':completion:*:hosts' hosts 'reply=( ${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*} ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}})'
ttyctl -f
# initialize completion
compinit -u -d "$compfile"
# initialize prompt with a decent built-in theme
promptinit
prompt adam1
# aliases
alias pcin='sudo pacman -S'
alias pcup='sudo pacman -Syyu'
alias pcrm='sudo pacman -Rns'
alias untar='tar -xvf'
[[ -r $HOME/Dark/aliases.zsh ]] && source $HOME/Dark/aliases.zsh
# initialize starship prompt syntax highlighting theme
[[ -f "$(which starship)" ]] && eval "$(starship init zsh)"
[[ -r $HOME/.local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] && source ~/.local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
[[ -r $HOME/zsh/plugins/sudo.plugin.zsh ]] && source $HOME/zsh/plugins/sudo.plugin.zsh
[[ -r $HOME/zsh/themes/blox-zsh-theme/blox.zsh ]] && source $HOME/zsh/themes/blox-zsh-theme/blox.zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment