Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / zsh / zsh-workshop
1 zsh-workshop - 20061128
2 =======================
3
4 Preface
5 -------
6
7 The following documentation is *not* a full documentation of the zsh
8 workshop, it just documents some general stuff which might be useful for
9 workshop participants. Notice: some configuration/keybindings/... are not
10 set up on default zsh but used in link:http://grml.org/[grml]'s
11 configuration.
12
13 Zsh?
14 ----
15
16 ''Zsh is a shell designed for interactive use, although it is also a
17 powerful scripting language. Many of the useful features of bash, ksh, and
18 tcsh were incorporated into zsh; many original features were added. ''
19
20   -- http://zsh.dotsrc.org/
21
22 Merges the best from ksh, csh and bash! ('emulate sh + emulate ksh')
23
24 More than 100 builtins, ~150 options + >300 keybindings
25
26 Configuration files
27 -------------------
28
29   wget -O ~/.zshrc http://hg.grml.org/grml-etc-core/raw-file/tip/etc/skel/.zshrc
30   wget -O ~/.zshrc.global http://hg.grml.org/grml-etc-core/raw-file/tip/etc/zsh/zshrc
31
32 Useful modules and settings
33 ---------------------------
34
35   % setopt autocd && /tmp   # cd /tmp
36   % setopt append_history share_history histignorealldups
37
38   % autoload -U zmv        # zmv "programmable rename"
39   % zmv '* *' '$f:gs/ /_'  # Replace spaces in filenames with a underline
40
41   % autoload run-help      # esc-h
42   % autoload compinit && compinit
43   % autoload -U zed
44
45 TIP: run 'setopt ksh_option_print && setopt' to get a listing of all
46 current settings
47
48 Globbing / Glob Qualifier
49 -------------------------
50
51   % setopt extendedglob
52   % ls -d *.^c              # list all files excluding c-source files
53   % ls /etc/*(@)            # list symlinks only
54   % ls -l *.(png|jpg|gif)   # list pictures only
55   % ls *(*)                 # list executables only
56   % ls /etc/**/zsh          # which directories contain 'zsh'?
57   % ls **/*(-@)             # list dangling symlinks
58   % ls **/*(/^F)            # list empty directories
59
60 TIP: run 'H-Glob' on your grml system for getting help regarding globbing
61
62 Keybindings
63 -----------
64
65 Some very interesting ones (besides default 'bindkey'):
66
67   CTRL-d              complete / EOF
68   CTRL-l              clear-screen
69   CTRL-w              delete last word
70   CTRL-_              undo
71   TAB                 complete and take first result
72   ESC-.               insert last parameter of last typed command (similar to typing !$)
73   ESC-e               edit the current line in $EDITOR
74   ESC-h               call run-help for the 1st word on the commandline
75   ESC-m               insert last typed word
76   CTRL-E d            insert a timestamp on the commandline (yyyy-mm-dd)
77   CTRL-a              begin of line
78   CTRL-e              end of line
79   Alt-'               quote-line => ''
80   Alt-<number>-char   insert <number> of chars
81   Alt-?               which-command
82   CTRL-x+a            complete alias
83   CTRL-x+e            complete word
84   CTRL-k              kill line
85   CTRL-u              copy line
86   CTRL-w              copy last word
87   CTRL-y              yank (insert kill-ring)
88
89 TIP: run "bindkey 'ctrl-v <keys>'" to find out which action is bount to a key
90
91 History
92 -------
93
94   % history
95   % !23       # Re-execute history command 23
96   % ^foo^bar  # edit previous command replace foo by bar
97
98 Check your history for most frequently used commands and create
99 aliases/functions for them!
100
101   % print -l -- ${(o)history%% *} | uniq -c | sort -nr | head -n 10
102
103 "Unsorted Must Knows"
104 ---------------------
105
106   % rehash                  # important for bash-users
107   % ls /u/s/d/x/exa<TAB>    # try it :)
108   % dpkg -i ~deb/foo.deb    # hash for /var/cache/apt/archives
109   % ls ~doc                 # hash /usr/share/doc
110   % ls =vim                 # ls $(which vim)
111   % sort <f{oo,ubar}        # cat foo fubar | sort
112   % less <(gzip -cd foo.gz) # gzip -cd foo.gz && less foo
113   % ls >file1 >file2 >file3
114   % less <file1 <file2
115   % vared PATH
116   % cd -<tab>
117   % echo {23..42}
118   % alias -s txt=vim
119   % RPROMPT=%T
120   % precmd () { RPROMPT="%(?..:()%" }
121   % xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
122   % w3m http://www.bash2zsh.com/zsh_refcard/refcard.pdf
123   % man zsh-lovers
124
125 Ressources
126 ----------
127
128 TIP: run 'zsh-help' on your grml system to get some hints regarding zsh
129
130 * link:http://grml.org/zsh/[grml's zsh webpage]
131 * link:http://www.bash2zsh.com/[Book: From Bash to Z Shell: Conquering the Command Line]
132
133 About this document
134 -------------------
135
136 (c) Michael Prokop <mika@grml.org>; HTML version powered by link:http://www.methods.co.nz/asciidoc/[asciidoc].
137
138 // vim: ft=asciidoc autoindent textwidth=75 formatoptions=tcqn