Tue 31 May 2016 — Thu 16 May 2019

Z Shell

http://zshwiki.org/

It's like Korn Shell (ksh).

I'm currently using zsh v5.6.2.

Debugging

Start as zsh -f to disable your config.

If it works, read and fix your config.

Secure Mode

zsh -r

Prevents cd and others.

Line Editor

man zshzle

-e to use emacs keys

Extensible

Completion

man zshcompsys. Make sure to use the newer system.

Functions

You can extend zsh by writing functions.

They look a bit like C functions, but the signature is always empty (no named parameters).

There is an autoload command. Use this to tell zsh what file a named function lives in. It will be loaded when used.

Aliases

Aliases are defined using: alias this="that"

They can't have arguments/parameters.

Keys

Here is a cursor keys pattern, found with cat -v:

key basic shift ctrl alt
up ^[[A ^[[1;2A ^[[1;5A ^[[1;3A
down ^[[B ^[[1;2B ^[[1;5B ^[[1;3B
right ^[[C ^[[1;2C ^[[1;5C ^[[1;3C
left ^[[D ^[[1;2D ^[[1;5D ^[[1;3D
# Ctrl keys move the cursor forward and backward one word
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

# Alt keys do the same, because that's the behaviour in Emacs
bindkey '^[[1;3C' forward-word
bindkey '^[[1;3D' backward-word

Prompt

Set $PS1 and $RPS1 to set the left and right-hand sides of the prompt respectively.

zsh includes vcs_info to give you information about version control. Find out something about this using man zshcontrib. However, this manual is a bit nuts, so background reading on the web is probably required.

Array Variables

Define an array with thing=('first item' 'second item'), then access them with ${thing[1]}.

They are 1-indexed (unless you set the KSHARRAYS option).

Globbing

zsh has fancy globbing.

standard multi-character wildcard
thing.*
alternatives
thing.(txt|zip|exe)

Also, in zsh when you do parameter expansion (substitution), globals won't come into effect and the parameter won't be split on whitespace.

zsh prints an error if your glob doesn't match a file, unless you set the NONOMATCH option.

Jobs

zsh will tell you when your background jobs finish.

TODO A User's Guide to Z-Shell