Dup Ver Goto 📝

ZshSh

PT2/aw/os/shell does not exist
To
41 lines, 233 words, 1551 chars Page 'ZshSh' does not exist.

A lot of zsh things are the same as in bash, some things are slightly different. I'd recommend the book "From Bash to Z Shell" by Kiddle, Peek and Stephenson

Key bindings

bindkey                         # print out current keymap
bindkey 'key' command           # create binding
bindkey -r 'key'                # remove binding
bindkey -d                      # delete all bindings and reset to default
bindkey -e                      # switch to emacs mode
bindkey -v                      # switch to vi mode
bindkey '\C-d'       # show binding for Ctrl-D (note the backslash)
bindkey -M keymap_name          # print out mappings in keymap_name
bindkey -A new_bindings emacs   # new bindings based on emacs bindings
bindkey -N new_keymap           # new empty keymap
bindkey -D keymap_name          # delete keymap_name
bindkey -R -M keymap_name 'a-z' self-insert # usual behaviour for a-z
Key Timeout

When you bind, e.g.

C-xd -> print "hello"
C-xdx -> print "byebye"

then zsh doesn't know, if you press C-x, whether or not x is coming. The variable KEYTIMEOUT tells zsh how long to wait before assuming that the key combo is complete.

KEYTIMEOUT=<hundredths of a second>    # e.g.
KEYTIMEOUT=200                         # two seconds

Shell options

setopt +o no match # pass through unmatched command line wildcard arguments

Pattern matching

if [[ $x = *hello ]]; then echo hello; fi # test for string ending with 'hello'