Set up the history file.
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# save each command's beginning timestamp and the duration to the history file
setopt extended_history
zstyle :compinstall filename '/home/kevin/.zshrc'
# display PID when suspending processes as well
setopt longlistjobs
autoload -Uz compinit
compinit
# in order to use #, ~ and ^ for filename generation grep word
# *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
# don't forget to quote '^', '~' and '#'!
setopt extended_glob
# autocompletion of command line switches for aliases
setopt COMPLETE_ALIASES
Completion for kitty
# kitty + complete setup zsh | source /dev/stdin
Autocompletion of privileged environments in privileged commands, e.g. sudo
zstyle ':completion::complete:*' gain-privileges 1
zstyle ':completion:*' menu select
some things from zsh-lovers https://grml.org/zsh/zsh-lovers.html
Fuzzy matching of completions for when you mistype them:
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
And if you want the number of errors allowed by _approximate to increase with the length of what you have typed so far:
zstyle -e ':completion:*:approximate:*' \
max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
Ignore completion functions for commands you don’t have:
zstyle ':completion:*:functions' ignored-patterns '_*'
With helper functions like:
xdvi() { command xdvi ${*:-*.dvi(om[1])} }
you can avoid having to complete at all in many cases, but if you do, you might want to fall into menu selection immediately and to have the words sorted by time:
zstyle ':completion:*:*:xdvi:*' menu yes select
zstyle ':completion:*:*:xdvi:*' file-sort time
export PATH="$HOME/bin:$HOME/.local/bin:/usr/local/bin:$HOME/.node_modules/bin:$(ruby -e 'print Gem.user_dir')/bin:$HOME/.config/composer/vendor/bin:$PATH"
Set up nvm
to use different verions of node
if [[ "$OSTYPE" == "linux-gnu" ]]; then
source /usr/share/nvm/init-nvm.sh
elif [[ "$OSTYPE" == "darwin"* ]]; then
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
fi
Set up paths for pyenv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Plugins installed from pacman
and brew
in different locations.
if [[ "$OSTYPE" == "linux-gnu" ]]; then
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh
fi
Custom prompt with snippets of code taken from various places.
The initial setup.
autoload -Uz promptinit vcs_info
promptinit
If set, parameter expansion, command substitution and arithmetic expansion are performed in prompts. Substitutions within prompts do not affect the command status.
setopt prompt_subst
Set up how git is displayed.
- based off https://stackoverflow.com/a/12935606
- green dot is staged
- yellow dot is unstaged
- red dot is untracked
zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:*' unstagedstr '●'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' actionformats '%F{5}[%F{4}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats \
'%F{8}[%F{7}±%B%b%%b %F{2}%c%F{3}%u%F{8}]%f' # %%b is bold off
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
}
precmd() {
vcs_info
}
Set up the actual prompt.
# from robbyrussel
# show a green error if the exit code is 0, otherwise show a red arrow
ret_status="%(?:%F{green}λ%f:%F{red}λ%f)"
newline=$'\n'
PROMPT='${newline}%B%F{cyan}%6~%f ${ret_status}%b '
RPROMPT='${vcs_info_msg_0_}'
Pacman aliases
alias pac='sudo pacman'
alias pacs='pac -S'
alias pacu='pac -Syu'
alias pacy='pac -Sy'
alias pacss='pac -Ss'
alias pacq='pac -Qs'
Xorg aliases
alias x='startx'
List aliases
alias ll='ls -l'
alias lla='ls -la'
Navigate around folders
alias '..'='cd ../'
alias '...'='cd ../../'
Git aliases
alias g='git'
alias gs='git status'
alias gss='git status -s'
Aliases to sync my KeePass db
alias keepush='CUR=$PWD && cd ~/gdrive && drive push KeePass && cd $CUR'
alias keepull='CUR=$PWD && cd ~/gdrive && drive pull KeePass && cd $CUR'
Use emacs-sandbox.sh to use basemacs
alias basemacs='emacs-sandbox.sh -PRd ~/.basemacs/'
# alias basemacs='emacs --with-profile base'
Set up things for vterm in Emacs
Some of the most useful features in vterm (e.g., directory-tracking and prompt-tracking or message passing) require shell-side configurations. The main goal of these additional functions is to enable the shell to send information to vterm via properly escaped sequences. A function that helps in this task, vterm_printf, is defined below. This function is widely used throughout this readme.
vterm_printf(){
if [ -n "$TMUX" ]; then
# Tell tmux to pass the escape sequences through
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
vterm-clear-scrollback does exactly what the name suggests: it clears the current buffer from the data that it is not currently visible. vterm-clear-scrollback is bound to C-c C-l. This function is typically used with the clear function provided by the shell to clear both screen and scrollback. In order to achieve this behavior, you need to add a new shell alias.
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear'
fi
The delete key by default inserts a ~, this makes it act like it should
bindkey "^[[3~" delete-char