1. .zshrc

zsh is my login and interactive shell but as my environment variables are all defined within environment.d (which allows a set of user services to share a common environment) there is no need to have the standard .zshenv or .zprofile files.

1.1. Startup

Autoload compinit, a module that provides completions for zsh.

autoload -Uz compinit

Speed up compinit by using zcompdump, a completion caching solution.

compinit -d /home/grtcdr/.cache/zsh/zcompdump

1.2. Common options

setopt append_history
setopt extended_history
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_no_store
setopt complete_aliases
setopt share_history
setopt ignore_eof
setopt list_packed
setopt auto_remove_slash
setopt no_complete_aliases

See the manual for more information on the above options.

1.3. Completions

zstyle ':completion:*' menu select      # Display completions
zstyle ':completion:*' use-cache on     # Cache completions
zstyle ':completion:*' file-sort access # Sort files by access

For more information, see zshcompsys(1).

1.4. Prompt

PROMPT="%(4~|.../%2~|%~) $ "

1.5. Aliases

I prefer to have commands that perform changes to the filesystem to be verbose and to always prompt me for my confirmation (a protective measure).

To bypass the prompts, use the yes command, e.g. yes | <cp,rm,mv> [OPTIONS].

alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -iv'

What is the possibly the most used command should be the quickest to access, here's a few aliases that make it more intuitive and colorful.

alias ls='ls --color=always --group-directories-first'
alias la='ls -la'
alias ll='ls -l'

cd is aliased to cdls to automate discovery, making movement between directories a bit more intuitive.

alias cd='cdls'
alias ..='cd ..'

Browse the list of installed packages and their metadata:

alias pkglist='pacman -Qq | fzf --preview-window sharp --preview "pacman -Qi {1}"'

Browse the list of packages available for download:

alias pkgsearch='pacman -Slq | fzf --multi --preview "pacman -Si {1}" | xargs -ro sudo pacman -S'

And everything else…

alias open="xdg-open"
alias wget="wget --no-hsts"
alias mbsync="mbsync --config "$HOME"/.config/mbsync/mbsyncrc"
alias vim="nvim"
alias music="ncmpcpp -q"

1.6. Functions

Define a function that lists the contents of directories upon entering them, it is aliased to cd section 1.5.

cdls() {
   builtin cd "$@" && ls

Define a function that brings programs to the foreground the same way they were placed in the background, originally authored by Adam Stankiewicz in his "How to boost your Vim productivity" publication.

fancy-ctrl-z() {
    if [[ $#BUFFER -eq 0 ]]; then
        zle accept-line -w
        zle push-input -w
        zle clear-screen -w

Load the functions:

zle -N fancy-ctrl-z

1.7. Keybindings

bindkey '^Z' fancy-ctrl-z
bindkey -e

1.8. Plugins

autojump, or simply j, remembers the places across the filesystem that one visits, allowing one to quickly jump between them by typing a small fraction (or component) of the path in mind.

source /usr/share/autojump/autojump.zsh