Skip to content

Instantly share code, notes, and snippets.

@Gavinok
Last active January 26, 2021 14:57
Show Gist options
  • Save Gavinok/aa40945e258d5745ea2e0626fd5933a5 to your computer and use it in GitHub Desktop.
Save Gavinok/aa40945e258d5745ea2e0626fd5933a5 to your computer and use it in GitHub Desktop.
my current .zshrc as of Mon 30 Nov 2020
## HISTORY
HISTFILE="${XDG_CACHE_HOME}/zsh_history"
HISTSIZE=1000
SAVEHIST=1000
#go to the directory without using cd
setopt autocd
export NNN_OPENER='open'
# Reclaim CTRL-S for use, e.g., with Vim (see: man stty)
stty -ixon
unsetopt flow_control
precmd () {
eval "$PROMPT_COMMAND"
vcs_info
# use beam shape cursor on startup.
echo -ne '\e[5 q'
}
preexec () {
# print the current running command as the title
printf '\e]0;%s\a' "${(V)1}"
}
# autoload -U promptinit; promptinit
PROMPT='%F{7}%(5~|%-1~/.../%2~|%4~) %(?.%F{14}.%F{red})% ᛋ ${vcs_info_msg_0_} %F{7}' #dark
#PROMPT=' %F{0}%(5~|%-1~/.../%2~|%4~) %(?.%F{0}.%F{red})%; ${vcs_info_msg_0_}' #light
# git status
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' stagedstr '⚫'
zstyle ':vcs_info:*' unstagedstr '⚪'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' actionformats '%F{5}%F{8}%b%F{3}|%F{1}%a%F{5} %f '
zstyle ':vcs_info:*' formats \
'%F{5}%F{6}%b%F{5} %F{5}%c%F{3}%u%f'
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
zstyle ':vcs_info:*' enable git
+vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
[[ $(git ls-files --other --directory --exclude-standard | sed q | wc -l | tr -d ' ') == 1 ]] ; then
hook_com[unstaged]+='%F{1}*%f'
fi
}
# autocompletion CLI switches for aliases
setopt completealiases
# Case Insensitive Completion and semi fuzzy
# 2x control is completion from history!!!
zle -C hist-complete complete-word _generic
zstyle ':completion:*' menu select
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.cache/zsh_completion_cache
# better completion for killall
zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'
zmodload zsh/complist
# case insensitive path-completion with dmenu like expansion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# partial completion suggestions (eg Doc/gro/expands to Documents/groff/)
zstyle ':completion:*' list-suffixes
zstyle ':completion:*' expand prefix suffix
## completion stuff
zstyle ':compinstall' filename '$HOME/.zshrc'
zcachedir="${XDG_CACHE_HOME}/zcache"
[[ -d "$zcachedir" ]] || mkdir -p "$zcachedir"
_update_zcomp() {
setopt local_options
setopt extendedglob
autoload -Uz compinit
local zcompf="${zcachedir}/zcompdump"
# use a separate file to determine when to regenerate, as compinit doesn't
# always need to modify the compdump
local zcompf_a="${zcompf}.augur"
if [[ -e "$zcompf_a" && -f "$zcompf_a"(#qN.md-1) ]]; then
compinit -C -d "$zcompf"
else
compinit -d "$zcompf"
touch $zcompf_a
fi
# if zcompdump exists (and is non-zero), and is older than the .zwc file,
# then regenerate
if [[ -s "$zcompf" && (! -s "${zcompf}.zwc" || "$zcompf" -nt "${zcompf}.zwc") ]]; then
# since file is mapped, it might be mapped right now (current shells), so
# rename it then make a new one
[[ -e "$zcompf.zwc" ]] && mv -f "$zcompf.zwc" "$zcompf.zwc.old"
# compile it mapped, so multiple shells can share it (total mem reduction)
# run in background
zcompile -M "$zcompf" &!
fi
}
_update_zcomp "$zcachedir"
# force completion to update
forcecompinit() {
local zcompf="${zcachedir}/zcompdump"
autoload -Uz compinit
compinit -C -d "$zcompf"
}
# vim mode config
# ---------------
# Activate vim mode.
bindkey -v
zle -N Resume
bindkey "^Z" Resume
cdUndoKey() {
popd
zle reset-prompt
echo
zle reset-prompt
}
zle -N cdUndoKey
bindkey '^O' cdUndoKey
# reverse search wth sift tab
bindkey '^[[Z' reverse-menu-complete
bindkey '^N' menu-complete
bindkey '^P' reverse-menu-complete
bindkey '^A' beginning-of-line
bindkey '^B' backward-char
bindkey '^F' forward-char
bindkey '^[f' forward-word
bindkey '^[b' backward-word
# bindkey -r vicmd ':' vi-cmd-mode
bindkey -v '^?' backward-delete-char
bindkey -M vicmd " " history-incremental-pattern-search-backward
# Open line in $EDITOR
autoload edit-command-line; zle -N edit-command-line
bindkey '^v' edit-command-line
# Enter vim buffer from normal mode
autoload -U edit-command-line && zle -N edit-command-line && bindkey -M vicmd "^v" edit-command-line
# exit zsh
exit_zsh() { exit }
zle -N exit_zsh
bindkey '^D' exit_zsh
# Remove mode switching delay.
KEYTIMEOUT=1
# Change cursor shape for different vi modes.
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne '\e[1 q'
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then
echo -ne '\e[5 q'
fi
}
zle -N zle-keymap-select
# ci", ci', ci`, di", etc
autoload -U select-quoted
zle -N select-quoted
for m in visual viopp; do
for c in {a,i}{\',\",\`}; do
bindkey -M $m $c select-quoted
done
done
# ci{, ci(, ci<, di{, etc
autoload -U select-bracketed
zle -N select-bracketed
for m in visual viopp; do
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
bindkey -M $m $c select-bracketed
done
done
# Allow Ctrl-z to toggle between suspend and resume
function Resume {
fg
zle push-input
BUFFER=""
zle accept-line
}
# Change the window title of X terminals
case ${TERM} in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*|st*)
PROMPT_COMMAND='echo -ne "\033]0;Terminal ${PWD/#$HOME/~}\007"'
;;
screen*)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
;;
esac
source $HOME/.config/aliasrc
source $HOME/.config/shortcutrc
source /usr/share/fzf/completion.zsh
source $HOME/.scripts/functions
if [ -f ~/.config/localprofile ];then
source $HOME/.config/localprofile
fi
# setup dirstack for use with <C-O> binding
DIRSTACKSIZE='20'
setopt AUTO_PUSHD PUSHD_SILENT PUSHD_TO_HOME
## Remove duplicate entries
setopt PUSHD_IGNORE_DUPS
## This reverts the +/- operators.
setopt PUSHD_MINUS
# Setup cdr
if [[ -z "$ZSH_CDR_DIR" ]]; then
ZSH_CDR_DIR=${XDG_CACHE_HOME:-$HOME/.cache}/zsh-cdr
fi
mkdir -p $ZSH_CDR_DIR
autoload -Uz chpwd_recent_dirs cdr
autoload -Uz add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':chpwd:*' recent-dirs-file $ZSH_CDR_DIR/recent-dirs
zstyle ':chpwd:*' recent-dirs-max 1000
# fall through to cd
zstyle ':chpwd:*' recent-dirs-default yes
# fzf-cdr
# requires sor (https://github.com/google/walk)
alias cdd='fzf-cdr'
function fzf-cdr() {
target_dir=$(cdr -l | sed -e 's/^[^ ][^ ]* *//' -e "s|~|$HOME|g" | sor 'test -d' | sed "s|$HOME|~|g" | fzf)
target_dir=$(echo ${target_dir/\~/$HOME})
if [ -d "$target_dir" ]; then
cd $target_dir
fi
}
# Plugins are Installed by ~/.profile
export ZSH_AUTOSUGGEST_USE_ASYNC=1
export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
source ${XDG_DATA_HOME}/zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment