Notes to Self

Alex Sokolsky's Notes on Computers and Programming

zsh

Must read ohmyzsh

Config

zsh startup

.zshenv → [.zprofile if login] → [.zshrc if interactive] → [.zlogin if login] → [.zlogout sometimes]

.zshenv is always sourced. It contains exported variables that should be available to other programs, e.g. $PATH, $EDITOR, $PAGER.

.zprofile is the same as .zlogin except that it’s sourced before .zshrc while .zlogin is sourced after .zshrc. According to the zsh documentation:

.zprofile is meant as an alternative to .zlogin for ksh fans; the two are not intended to be used together, although this could certainly be done if desired.

.zshrc is for interactive shell configuration. You set options for the interactive shell there with the setopt and unsetopt commands. You can also:

You also set any variables that are only used in the interactive shell (e.g. $LS_COLORS).

.zlogin is sourced on the start of a login shell but after .zshrc if the shell is also interactive. This file is often used to start X. Some systems start X on boot, so this file is not always very useful.

.zshenv

# .zshenv is sourced on all invocations of the shell, unless the -f option is
# set. It should contain commands to set the command search path, plus other
# important environment variables.
# .zshenv should NOT contain commands that produce output or assume the shell
# is attached to a tty.

export PDSH_RCMD_TYPE=ssh

.zprofile

# .zprofile is similar to .zlogin, except that it is sourced before .zshrc.
# .zprofile is meant as an alternative to .zlogin for ksh fans;
# the two are not intended to be used together,
# although this could certainly be done.

eval "$(ssh-agent -s)"
#ssh-add ~/.ssh/id_rsa
ssh-add

.zshrc

```sh

.zshrc is sourced in interactive shells.

Should contain commands to set up aliases, functions, options, key bindings,

etc.

Set up the prompt

autoload -Uz promptinit promptinit prompt suse

setopt histignorealldups sharehistory

Use emacs keybindings even if our EDITOR is set to vi

bindkey -e

Keep 1000 lines of history within the shell and save it to ~/.zsh_history:

HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.zsh_history

Use modern completion system

autoload -Uz compinit compinit

zstyle ‘:completion:’ auto-description ‘specify: %d’ zstyle ‘:completion:’ completer expand _complete _correct _approximate zstyle ‘:completion:*’ format ‘Completing %d’ zstyle ‘:completion:*’ group-name ‘’ zstyle ‘:completion:*’ menu select=2 eval “$(dircolors -b)” zstyle ‘:completion:*:default’ list-colors ${(s.:.)LS_COLORS} zstyle ‘:completion:*’ list-colors ‘’ zstyle ‘:completion:*’ list-prompt %SAt %p: Hit TAB for more, or the character to insert%s zstyle ‘:completion:*’ matcher-list ‘’ ‘m:{a-z}={A-Z}’ ‘m:{a-zA-Z}={A-Za-z}’ ‘r:|[.-]=* r:|=* l:|=’ zstyle ‘:completion:’ menu select=long zstyle ‘:completion:’ select-prompt %SScrolling active: current selection at %p%s zstyle ‘:completion:’ use-compctl false zstyle ‘:completion:*’ verbose true

zstyle ‘:completion:::kill::processes’ list-colors ‘=(#b) #([0-9]#)=0=01;31’ zstyle ‘:completion::kill:’ command ‘ps -u $USER -o pid,%cpu,tty,cputime,cmd’