I have not been deep-diving into any shell, usually just used the default provided by various distributions, however I thought it was time to dive in at the semi-deep end and try to get an understanding of how it works and learn something. For this I selected zsh since i like how completions works, it was also the default in the install media i used. If one would be interested in another shell there are quite a few.1
Holy crap there is a lot of functions / options and stuff to a Z-shell. So the swim will not be that long.
autoload -Uz compinit promptinit
compinit
promptinit
prompt grml
bindkey -v
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt HIST_IGNORE_DUPS
if [[ -r ~/.aliasrc ]]; then
. ~/.aliasrc
fi
For reference and learning I will go through each line in the config and explain what it do.
autoload -Uz compinit promptinit
The autoload directive marks the function compinit and promptinit as undefined2 and then searches the fpath for the functions, rather than the PATH variable for executables. The -U
options suppresses any alias expansion3 and the -z
marks the function to be auto loaded using zsh style
echo $FPATH
will print the directories listed in that environment variable
compinit
will execute the script /usr/share/zsh/functions/Completion/compinit
promptinit
will execute the script /usr/share/zsh/functions/Prompts/promptinit
prompt grml
load the grml theme for prompt, worth noting since this was not auto loaded its and executable. There are a number of available prompts, you can view how the look by running prompt -p
. If one would be really interested in tweaking the prompt, one could edit the $PS1
variable for the default prompt or the additional 3 prompts.
bindkey -v
will put zsh into vi-mode however it is worth noting that you will start in insert mode, so you will have to press ‘ESC’ to be able to enter vi commands
HISTSIZE=1000
, this option will tell zsh the number (in this case 1000) of lines to load from history when a shell is loaded.
SAVEHIST=1000
, this option tells the shell how many lines to store in history when exiting
HISTFILE=~/.zsh_history
tell zsh where to store history.
SHARE_HISTORY
Causes shell to import history-commands from history file, it will also append history as typed to history file.4
HIST_IGNORE_DUPS
This command tells the shell not to store duplicates of commands.4
It is probably nice to have an alias file, .aliassrc to have a clean .zshrc
if [[ -r ~/.aliasrc ]]; then
. ~/.aliasrc
fi
Note .
before ~/.aliasrc
is the same as source
(Thanks for this)5