Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / zsh / zsh-lovers.1
1 '\" t
2 .\"     Title: zsh-lovers
3 .\"    Author: [see the "AUTHORS" section]
4 .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
5 .\"      Date: 04/03/2014
6 .\"    Manual: \ \&
7 .\"    Source: \ \&
8 .\"  Language: English
9 .\"
10 .TH "ZSH\-LOVERS" "1" "04/03/2014" "\ \&" "\ \&"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 zsh-lovers \- tips, tricks and examples for the Z shell
32 .SH "SYNOPSIS"
33 .sp
34 Just read it\&. ;\-)
35 .SH "OVERVIEW"
36 .sp
37 Whenever we look at the zsh manual we wonder why there are no examples or those simply things in (shell) life\&. The zsh contains many features, but there was no manpage with some examples (like procmailex(5))\&. That\(cqs why we wrote this manpage\&.
38 .sp
39 Most of the tricks and oneliner come from the mailinglists zsh\-users, zsh\-workers, google, newsgroups and from ourself\&. See section \fBLINKS\fR for details\&.
40 .sp
41 Note: This manpage (zsh\-lovers(1)) is \fBnot\fR an offical part of the Z shell! It\(cqs just a just for fun \- manpage ;) For comments, bugreports and feedback take a quick look at the section \fBBUGS\fR\&.
42 .SH "SHELL-SCRIPTING"
43 .sp
44 This section provides some examples for often needed shellscript\-stuff\&. Notice that you should not use otherwise most examples won\(cqt work\&. Parse options in shellscripts\&. Example taken from ZWS by Adam Chodorowski (http://www\&.chodorowski\&.com/projects/zws/):
45 .sp
46 .if n \{\
47 .RS 4
48 .\}
49 .nf
50 parse_options()
51 {
52     o_port=(\-p 9999)
53     o_root=(\-r WWW)
54     o_log=(\-d ZWS\&.log)
55
56     zparseopts \-K \-\- p:=o_port r:=o_root l:=o_log h=o_help
57     if [[ $? != 0 || "$o_help" != "" ]]; then
58         echo Usage: $(basename "$0") "[\-p PORT] [\-r DIRECTORY]"
59         exit 1
60     fi
61
62     port=$o_port[2]
63     root=$o_root[2]
64     log=$o_log[2]
65
66     if [[ $root[1] != \*(Aq/\*(Aq ]]; then root="$PWD/$root"; fi
67 }
68 # now use the function:
69 parse_options $*
70 .fi
71 .if n \{\
72 .RE
73 .\}
74 .SH "EXAMPLES"
75 .sp
76 Available subsections are \fBAliases\fR, \fBCompletion\fR, \fBUnsorted/Misc examples\fR, \fB(Recursive) Globbing \- Examples\fR, \fBModifiers usage\fR, \fBRedirection\-Examples\fR, \fBZMV\-Examples\fR and \fBModule\-Examples\fR\&.
77 .SS "ALIASES"
78 .sp
79 Suffix aliases are supported in zsh since version 4\&.2\&.0\&. Some examples:
80 .sp
81 .if n \{\
82 .RS 4
83 .\}
84 .nf
85 alias \-s tex=vim
86 alias \-s html=w3m
87 alias \-s org=w3m
88 .fi
89 .if n \{\
90 .RE
91 .\}
92 .sp
93 Now pressing return\-key after entering \fIfoobar\&.tex\fR starts vim with foobar\&.tex\&. Calling a html\-file runs browser w3m\&. \fIwww\&.zsh\&.org\fR and pressing enter starts w3m with argument www\&.zsh\&.org\&. Global aliases can be used anywhere in the command line\&. Example:
94 .sp
95 .if n \{\
96 .RS 4
97 .\}
98 .nf
99 $ alias \-g C=\*(Aq| wc \-l\*(Aq
100 $ grep alias ~/\&.zsh/* C
101 443
102 .fi
103 .if n \{\
104 .RE
105 .\}
106 .sp
107 Some more or less useful global aliases (choose whether they are useful or not for you on your own):
108 .sp
109 .if n \{\
110 .RS 4
111 .\}
112 .nf
113 alias \-g \&.\&.\&.=\*(Aq\&.\&./\&.\&.\*(Aq
114 alias \-g \&.\&.\&.\&.=\*(Aq\&.\&./\&.\&./\&.\&.\*(Aq
115 alias \-g \&.\&.\&.\&.\&.=\*(Aq\&.\&./\&.\&./\&.\&./\&.\&.\*(Aq
116 alias \-g CA="2>&1 | cat \-A"
117 alias \-g C=\*(Aq| wc \-l\*(Aq
118 alias \-g D="DISPLAY=:0\&.0"
119 alias \-g DN=/dev/null
120 alias \-g ED="export DISPLAY=:0\&.0"
121 alias \-g EG=\*(Aq|& egrep\*(Aq
122 alias \-g EH=\*(Aq|& head\*(Aq
123 alias \-g EL=\*(Aq|& less\*(Aq
124 alias \-g ELS=\*(Aq|& less \-S\*(Aq
125 alias \-g ETL=\*(Aq|& tail \-20\*(Aq
126 alias \-g ET=\*(Aq|& tail\*(Aq
127 alias \-g F=\*(Aq | fmt \-\*(Aq
128 alias \-g G=\*(Aq| egrep\*(Aq
129 alias \-g H=\*(Aq| head\*(Aq
130 alias \-g HL=\*(Aq|& head \-20\*(Aq
131 alias \-g Sk="*~(*\&.bz2|*\&.gz|*\&.tgz|*\&.zip|*\&.z)"
132 alias \-g LL="2>&1 | less"
133 alias \-g L="| less"
134 alias \-g LS=\*(Aq| less \-S\*(Aq
135 alias \-g MM=\*(Aq| most\*(Aq
136 alias \-g M=\*(Aq| more\*(Aq
137 alias \-g NE="2> /dev/null"
138 alias \-g NS=\*(Aq| sort \-n\*(Aq
139 alias \-g NUL="> /dev/null 2>&1"
140 alias \-g PIPE=\*(Aq|\*(Aq
141 alias \-g R=\*(Aq > /c/aaa/tee\&.txt \*(Aq
142 alias \-g RNS=\*(Aq| sort \-nr\*(Aq
143 alias \-g S=\*(Aq| sort\*(Aq
144 alias \-g TL=\*(Aq| tail \-20\*(Aq
145 alias \-g T=\*(Aq| tail\*(Aq
146 alias \-g US=\*(Aq| sort \-u\*(Aq
147 alias \-g VM=/var/log/messages
148 alias \-g X0G=\*(Aq| xargs \-0 egrep\*(Aq
149 alias \-g X0=\*(Aq| xargs \-0\*(Aq
150 alias \-g XG=\*(Aq| xargs egrep\*(Aq
151 alias \-g X=\*(Aq| xargs\*(Aq
152 .fi
153 .if n \{\
154 .RE
155 .\}
156 .SS "COMPLETION"
157 .sp
158 See also man 1 zshcompctl zshcompsys zshcompwid\&. zshcompctl is the old style of zsh programmable completion, zshcompsys is the new completion system, zshcompwid are the zsh completion widgets\&.
159 .sp
160 Some functions, like _apt and _dpkg, are very slow\&. You can use a cache in order to proxy the list of results (like the list of available debian packages) Use a cache:
161 .sp
162 .if n \{\
163 .RS 4
164 .\}
165 .nf
166 zstyle \*(Aq:completion:*\*(Aq use\-cache on
167 zstyle \*(Aq:completion:*\*(Aq cache\-path ~/\&.zsh/cache
168 .fi
169 .if n \{\
170 .RE
171 .\}
172 .sp
173 Prevent CVS files/directories from being completed:
174 .sp
175 .if n \{\
176 .RS 4
177 .\}
178 .nf
179 zstyle \*(Aq:completion:*:(all\-|)files\*(Aq ignored\-patterns \*(Aq(|*/)CVS\*(Aq
180 zstyle \*(Aq:completion:*:cd:*\*(Aq ignored\-patterns \*(Aq(*/)#CVS\*(Aq
181 .fi
182 .if n \{\
183 .RE
184 .\}
185 .sp
186 Fuzzy matching of completions for when you mistype them:
187 .sp
188 .if n \{\
189 .RS 4
190 .\}
191 .nf
192 zstyle \*(Aq:completion:*\*(Aq completer _complete _match _approximate
193 zstyle \*(Aq:completion:*:match:*\*(Aq original only
194 zstyle \*(Aq:completion:*:approximate:*\*(Aq max\-errors 1 numeric
195 .fi
196 .if n \{\
197 .RE
198 .\}
199 .sp
200 And if you want the number of errors allowed by _approximate to increase with the length of what you have typed so far:
201 .sp
202 .if n \{\
203 .RS 4
204 .\}
205 .nf
206 zstyle \-e \*(Aq:completion:*:approximate:*\*(Aq \e
207         max\-errors \*(Aqreply=($((($#PREFIX+$#SUFFIX)/3))numeric)\*(Aq
208 .fi
209 .if n \{\
210 .RE
211 .\}
212 .sp
213 Ignore completion functions for commands you don\(cqt have:
214 .sp
215 .if n \{\
216 .RS 4
217 .\}
218 .nf
219 zstyle \*(Aq:completion:*:functions\*(Aq ignored\-patterns \*(Aq_*\*(Aq
220 .fi
221 .if n \{\
222 .RE
223 .\}
224 .sp
225 With helper functions like:
226 .sp
227 .if n \{\
228 .RS 4
229 .\}
230 .nf
231 xdvi() { command xdvi ${*:\-*\&.dvi(om[1])} }
232 .fi
233 .if n \{\
234 .RE
235 .\}
236 .sp
237 you can avoid having to complete at all in many cases, but if you do, you might want to fall into menu selection immediately and to have the words sorted by time:
238 .sp
239 .if n \{\
240 .RS 4
241 .\}
242 .nf
243 zstyle \*(Aq:completion:*:*:xdvi:*\*(Aq menu yes select
244 zstyle \*(Aq:completion:*:*:xdvi:*\*(Aq file\-sort time
245 .fi
246 .if n \{\
247 .RE
248 .\}
249 .sp
250 Completing process IDs with menu selection:
251 .sp
252 .if n \{\
253 .RS 4
254 .\}
255 .nf
256 zstyle \*(Aq:completion:*:*:kill:*\*(Aq menu yes select
257 zstyle \*(Aq:completion:*:kill:*\*(Aq   force\-list always
258 .fi
259 .if n \{\
260 .RE
261 .\}
262 .sp
263 If you end up using a directory as argument, this will remove the trailing slash (usefull in ln)
264 .sp
265 .if n \{\
266 .RS 4
267 .\}
268 .nf
269 zstyle \*(Aq:completion:*\*(Aq squeeze\-slashes true
270 .fi
271 .if n \{\
272 .RE
273 .\}
274 .sp
275 cd will never select the parent directory (e\&.g\&.: cd \&.\&./<TAB>):
276 .sp
277 .if n \{\
278 .RS 4
279 .\}
280 .nf
281 zstyle \*(Aq:completion:*:cd:*\*(Aq ignore\-parents parent pwd
282 .fi
283 .if n \{\
284 .RE
285 .\}
286 .sp
287 Another method for \fIquick change directories\fR\&. Add this to your ~/\&.zshrc, then just enter \(lqcd \&...\&./dir\(rq
288 .sp
289 .if n \{\
290 .RS 4
291 .\}
292 .nf
293 rationalise\-dot() {
294   if [[ $LBUFFER = *\&.\&. ]]; then
295     LBUFFER+=/\&.\&.
296   else
297     LBUFFER+=\&.
298   fi
299 }
300 zle \-N rationalise\-dot
301 bindkey \&. rationalise\-dot
302 .fi
303 .if n \{\
304 .RE
305 .\}
306 .SS "UNSORTED/MISC examples"
307 .sp
308 Hint: A list of valid glob Qualifiers can be found in zshexpn(1)\&. See \(lqman 1 zshexpn | less \-p\(rq Qualifiers for details\&.
309 .sp
310 .if n \{\
311 .RS 4
312 .\}
313 .nf
314 # Get the names of all files that *don\*(Aqt* match a pattern *anywhere* on the
315 # file (and without ``\-L\*(Aq\*(Aq because its GNUish)
316   $ print \-rl \-\- *(\&.^e{\*(Aqgrep \-q pattern $REPLY\*(Aq})
317   # or
318   $ : *(\&.e{\*(Aqgrep \-q pattern $REPLY || print \-r \-\- $REPLY\*(Aq})
319
320 # random numbers
321   $ echo $[${RANDOM}%1000]     # random between 0\-999
322   $ echo $[${RANDOM}%11+10]    # random between 10\-20
323   $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)
324
325 # reverse a word
326   $ echo "${(j::)${(@Oa)${(s::):\-hello}}}"
327
328 # Show newest directory
329   $ ls \-ld *(/om[1])
330
331 # random array element
332   $ FILES=( \&.\&.\&./files/* )
333   $ feh $FILES[$RANDOM%$#FILES+1]
334
335 # cat first line in all files in this dir
336   $ for file (*(ND\-\&.)) IFS= read \-re < $file
337
338 # test if a parameter is numeric
339   $ if [[ $1 == <\-> ]] ; then
340          echo numeric
341     else
342          echo non\-numeric
343     fi
344
345 # Show me all the \&.c files for which there doesn\*(Aqt exist a \&.o file\&.
346   $ print *\&.c(e_\*(Aq[[ ! \-e $REPLY:r\&.o ]]\*(Aq_)
347
348 # All files in /var/ that are not owned by root
349   $ ls \-ld /var/*(^u:root)
350
351 # All files for which the owner hat read and execute permissions
352   $ echo *(f:u+rx:)
353
354 # The same, but also others dont have execute permissions
355   $ echo *(f:u+rx,o\-x:)
356
357 # brace expansion \- example
358   $ X=(A B C)
359   $ Y=(+ \-)
360   $ print \-r \-\- $^X\&.$^Y
361   A\&.+ A\&.\- B\&.+ B\&.\- C\&.+ C\&.\-
362
363 # Fetch the newest file containing the string \*(Aqfgractg*\&.log\*(Aq in the
364 # filename and contains the string \*(AqORA\-\*(Aq in it
365   $ file=(fgractg*\&.log(Nm0om[1]))
366   $ (($#file)) && grep \-l ORA\- $file
367   # without Zsh
368   $ files=$( find \&. \-name \&. \-o \-prune \-name \*(Aqfgractg*>log\*(Aq \-mtime 0 \-print )
369   > if [ \-n "$files" ]; then
370   >    IFS=\*(Aq
371   > \*(Aq
372   > set \-f
373   > file=$(ls \-td $files | head \-1)
374   > grep \-l ORA\- "$file"
375   > fi
376
377 # keep specified number of child processes running until entire task finished
378   $ zsh \-c \*(Aqsleep 1 & sleep 3 & sleep 2& print \-rl \-\- $jobtexts\*(Aq
379
380 # Remove zero length and \&.bak files in a directory
381   $ rm \-i *(\&.L0) *\&.bak(\&.)
382
383 # print out files that dont have extensions
384   $ printf \*(Aq%s\en\*(Aq ^?*\&.*
385   $ printf \*(Aq%s\en\*(Aq ^?*\&.[^\&.]*(D)
386   $ ls \-d \-\- ^?*\&.*(D)
387
388 # Finding files which does not contain a specific string
389   $ print \-rl file* | comm \-2 \-3 \- <(grep \-l string file*)\*(Aq
390   $ for f (file*(N)) grep \-q string $f || print \-r $f\*(Aq
391
392 # Show/Check whether a option is set or not\&. It works both with $options as
393 # with $builtins
394   $ echo $options[correct]
395   off
396   $ $options[zle]
397   on
398
399 # Count the number of directories on the stack
400   $ print $((${${(z)${(f)"$(dirs \-v)"}[\-1]}[1]} + 1)) # or
401   $ dirs \-v | awk \*(Aq{n=$1}END{print n+1}\*(Aq
402
403 # Matching all files which do not have a dot in filename
404   $ ls *~*\&.*(\&.)
405
406 # Show only the ip\-address from ``ifconfig device\*(Aq\*(Aq
407   # ifconfig from net\-tools (Linux)
408   $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}
409   # ifconfig from 4\&.2BSD {Free,Net,Open}BSD
410   $ print ${$(/sbin/ifconfig tun0)[6]}
411
412 # Ping all the IP addresses in a couple of class C\*(Aqs or all hosts
413 # into /etc/hosts
414   $ for i in {1\&.\&.254}; do ping \-c 1 192\&.168\&.13\&.$i; done
415   or
416   $ I=1
417   $ while ( [[ $I \-le 255 ]] ) ; do ping \-1 2 150\&.150\&.150\&.$I; let I++; done
418   or
419   $ for i in $(sed \*(Aqs/#\&.*//\*(Aq > /etc/hosts | awk \*(Aq{print $2}\*(Aq)
420   : do
421   :    echo "Trying $i \&.\&.\&. "
422   :    ping \-c 1 $i ;
423   :    echo \*(Aq=============================\*(Aq
424   : done
425
426 # load all available modules at startup
427   $ typeset \-U m
428   $ m=()
429   $ for md ($module_path) m=($m $md/**/*(*e:\*(AqREPLY=${REPLY#$md/}\*(Aq::r))
430   $ zmodload \-i $m
431
432 # Rename all files within a directory such that their names get a numeral
433 # prefix in the default sort order\&.
434   $ i=1; for j in *; do mv $j $i\&.$j; ((i++)); done
435   $ i=1; for f in *; do mv $f $(echo $i | \e
436     awk \*(Aq{ printf("%03d", $0)}\*(Aq)\&.$f; ((i++)); done
437   $ integer i=0; for f in *; do mv $f $[i+=1]\&.$f; done
438
439 # Find (and print) all symbolic links without a target within the current
440 # dirtree\&.
441   $ $ file **/*(D@) | fgrep broken
442   $ for i in **/*(D@); [[ \-f $i || \-d $i ]] || echo $i
443   $ echo **/*(@\-^\&./=%p)
444   $ print \-l **/*(\-@)
445
446 # List all plain files that do not have extensions listed in `fignore\*(Aq
447   $ ls **/*~*(${~${(j/|/)fignore}})(\&.)
448   # see above, but now omit executables
449   $ ls **/*~*(${~${(j/|/)fignore}})(\&.^*)
450
451 # Print out files that dont have extensions (require *setopt extendedglob*
452 # and *setopt dotglob*)
453   $ printf \*(Aq%s\en\*(Aq ^?*\&.*
454
455 # List files in reverse order sorted by name
456   $ print \-rl \-\- *(On)
457   or
458   $ print \-rl \-\- *(^on)
459
460 # Synonymic to ``ps ax | awk \*(Aq{print $1}\*(Aq\*(Aq\*(Aq
461   $ print \-l /proc/*/cwd(:h:t:s/self//)
462
463 # Get the PID of a process (without ``ps\*(Aq\*(Aq, ``sed\*(Aq\*(Aq, ``pgrep\*(Aq\*(Aq, \&.\&.
464 # (under Linux)
465   $ pid2 () {
466   >   local i
467   >   for i in /proc/<\->/stat
468   > do
469   >   [[ "$(< $i)" = *\e((${(j:|:)~@})\e)* ]] && echo $i:h:t
470   > done
471   > }
472
473 # for X in \*(Aqn\*(Aq \*(Aqo\*(Aq \*(Aqp\*(Aq \*(Aqq\*(Aq \*(Aqr\*(Aq \*(Aqs\*(Aq \*(Aqt\*(Aq \*(Aqu\*(Aq \*(Aqv\*(Aq \*(Aqw\*(Aq \*(Aqx\*(Aq \*(Aqy\*(Aq; do \&.\&.\&.
474   $ for (( i = 36#n; i <= 36#y; i++ )); do
475   >   print ${$(([##36]i)):l}
476   > done
477 # or in combination with ``dc\*(Aq\*(Aq
478   $ print {$((##n))\&.\&.$((##y))}P\e 10P | dc
479 # or with ``eval\*(Aq\*(Aq
480   $ eval print \*(Aq${$(([##36]\*(Aq{$((36#n))\&.\&.$((36#y))}\*(Aq)):l}\*(Aq
481
482 # foreach in one line of shell
483   $ for f (*) print \-r \-\- $f
484
485 # copy a directory recursively without data/files
486   $ dirs=(**/*(/))
487   $ cd \-\- $dest_root
488   $ mkdir \-p \-\- $dirs
489 # or without zsh
490   $ find \&. \-type d \-exec env d="$dest_root" \e
491     sh \-c \*(Aq exec mkdir \-p \-\- "$d/$1"\*(Aq \*(Aq{}\*(Aq \*(Aq{}\*(Aq \e;
492
493 # If `foo=23\*(Aq\*(Aq, then print with 10 digit with leading \*(Aq0\*(Aq\&.
494   $ foo=23
495   $ print ${(r:10::0:)foo}
496
497 # find the name of all the files in their home directory that have
498 # more than 20 characters in their file names
499   print \-rl $HOME/${(l:20::?:)~:\-}*
500
501 # Save arrays
502   $ print \-r \-\- ${(qq)m} > $nameoffile      # save it
503   $ eval "m=($(cat \-\- $nameoffile)"            # or use
504   $ m=("${(@Q)${(z)"$(cat \-\- $nameoffile)"}}") # to restore it
505
506 # get a "ls \-l" on all the files in the tree that are younger than a
507 # specified age (e\&.g "ls \-l" all the files in the tree that where
508 # modified in the last 2 days)
509   $ ls \-tld **/*(m\-2)
510 # This will give you a listing 1 file perl line (not Ã  la ls \-R)\&.
511 # Think of an easy way to have a "ls \-R" style output with
512 # only files newer than 2 day old\&.
513   $ for d (\&. \&./**/*(/)) {
514   >   print \-r \-\- $\*(Aq\en\*(Aq${d}:
515   >   cd $d && {
516   >       l=(*(Nm\-2))
517   >       (($#l)) && ls \-ltd \-\- $l
518   >       cd ~\-
519   >   }
520   > }
521 # If you also want directories to be included even if their mtime
522 # is more than 2 days old:
523   $ for d (\&. \&./**/*(/)) {
524   >   print \-r \-\- $\*(Aq\en\*(Aq${d}:
525   >   cd $d && {
526   >      l=(*(N/,m\-2))
527   >      (($#l)) && ls \-ltd \-\- $l
528   >      cd ~\-
529   >   }
530   > }
531 # And if you want only the directories with mtime < 2 days to be listed:
532   $ for d (\&. \&./**/*(N/m\-2)) {
533   >   print \-r \-\- $\*(Aq\en\*(Aq${d}:
534   >   cd $d && {
535   >      l=(*(Nm\-2))
536   >      (($#l)) && ls \-ltd \-\- $l
537   >      cd ~\-
538   >   }
539   > }
540
541 # print 42 ``\-\*(Aq\*(Aq
542   $ echo ${(l:42::\-:)}
543 # or use ``$COLUMS\*(Aq\*(Aq
544   $ echo ${(l:$COLUMNS::\-:)}
545 # and now with colors (require autoload colors ;colors)
546   $ echo "$bg[red]$fg[black]${(l:42::\-:)}"
547
548 # Redirect STDERR to a command like xless without redirecting STDOUT as well\&.
549   $ foo 2>>(xless)
550 # but this executes the command asynchronously\&. To do it synchronously:
551   $ { { foo 1>&3 } 2>&1 | xless } 3>&1
552
553 # Rename all MP3\-Files from name with spaces\&.mp3 to Name With Spaces\&.mp3
554   $ for i in *\&.mp3; do
555   >     mv $i ${${(C)i}:s/Mp3/mp3/}
556   > done
557
558 # Match file names containing only digits and ending with \&.xml (require
559 # *setopt kshglob*)
560   $ ls \-l [0\-9]##\&.xml
561   $ ls \-l <0\->\&.xml
562
563 # Remove all "non txt" files
564   $ rm \&./^*\&.txt
565
566 # Move 200 files from a directory into another
567   $ mv \-\- *([1,200]) /another/Dir
568
569 # Convert images (foo\&.gif => foo\&.png):
570   $ for i in **/*\&.gif; convert $i $i:r\&.png
571
572 # convert a collection of mp3 files to wave or cdr,
573 # e\&.g\&. file\&.wav \-> file\&.mp3)
574   $ for i (\&./*\&.mp3){mpg321 \-\-w \- $i > ${i:r}\&.wav}
575
576 # Download with LaTeX2HTML  created Files (for example the ZSH\-Guide):
577   $ for f in http://zsh\&.sunsite\&.dk/Guide/zshguide{,{01\&.\&.08}}\&.html; do
578   >     lynx \-source $f >${f:t}
579   > done
580
581 # Move all files in dir1 and dir2 that have line counts greater than 10 to
582 # another directory say "/more10"
583   $ mv dir[12]/**/*\&.cr(\-\&.e{\*(Aq((`wc \-l < $REPLY` > 10))\*(Aq}) /more10
584
585 # Make with dpkg a master\-list of everyfile that it has installed
586   $ diff <(find / | sort) <(cat /var/lib/dpkg/info/*\&.list | sort)
587
588 # Replace this fucking Escape\-Sequences:
589   $ autoload colors ; colors
590   $ print "$bg[cyan]$fg[blue]You are a idiot" >> /dev/pts/3
591
592 # Get ASCII value of a character
593   $ char=N ; print $((#char))
594
595 # Filename "Erweiterung"
596 # Note: The (N) says to use the nullglob option for this particular
597 # glob pattern\&.
598   $ for i in *\&.o(N); do
599   >     rm $i
600   > done
601
602 # Rename files; i\&. e\&. FOO to foo and bar to BAR
603   $ for i in *(\&.); mv $i ${i:l} # `FOO\*(Aq to `foo\*(Aq
604   $ for i in *(\&.); mv $i ${i:u} # `bar to `BAR\*(Aq
605
606 # Show all suid\-files in $PATH
607   $ ls \-latg ${(s\&.:\&.)PATH} | grep \*(Aq^\&.\&.\&.s\*(Aq
608 # or more complex ;)
609   $ print \-l ${^path}/*(Ns,S)
610 # or show only executables with a user given pattern
611   $ print \-l ${^path}/*vim*(*N)
612
613 # gzip files when containing a certain string
614   $ gzip ${(ps:\e0:)"$(grep \-lZ foobar \&./*\&.txt(\&.))"}
615
616 # A small  one\-liner, that reads from stdin and prints to stdout the first
617 # unique line i\&. e\&. does not print lines that have been printed before
618 # (this is similar to the unique command, but unique can only handle
619 # adjacent lines)\&.
620   $ IFS=$\*(Aq\en\en\*(Aq; print \-rl \-\- ${(Oau)${(Oa)$(cat file;echo \&.)[1,\-2]}}
621
622 # Lists every executable in PATH
623   $ print \-l ${^path}/*(\-*N)
624
625 # Match all \&.c files in all subdirectories, _except_ any SCCS subdirectories?
626   $ ls **/*\&.c~(*/)#SCCS/*
627
628 # List all `README\*(Aq \- files case\-insensitive with max\&. one typo
629   $ ls **/*(#ia2)readme
630
631 # case insensitive checking for variables
632   $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then
633   >    echo "Penguin on board\&."
634   > else
635   >    echo "Not a Linux\&."
636   > fi
637 .fi
638 .if n \{\
639 .RE
640 .\}
641 .SS "(Recursive) Globbing \- Examples"
642 .sp
643 A list of valid glob Qualifiers can be found in zshexpn(1)\&. \fBNote:\fR **/ is equivalent to (*/)#! For example:
644 .sp
645 .if n \{\
646 .RS 4
647 .\}
648 .nf
649 $ print (*/)#zsh_us\&.ps
650 zsh\-4\&.2\&.3/Doc/zsh_us\&.ps
651 $ print **/zsh_us\&.ps
652 zsh\-4\&.2\&.3/Doc/zsh_us\&.ps
653 .fi
654 .if n \{\
655 .RE
656 .\}
657 .sp
658 .if n \{\
659 .RS 4
660 .\}
661 .nf
662 # Search for `README\*(Aq in all Subdirectories
663   $ ls \-l **/README
664
665 # find directories that contain both "index\&.php" and "index\&.html", or in
666 # general, directories that contain more than one file matching "index\&.*"
667   $ ls **/*(D/e:\*(Aq[[ \-e $REPLY/index\&.php && \-e $REPLY/index\&.html ]]\*(Aq:)
668   # or
669   $ ls **/*(D/e:\*(Aql=($REPLY/index\&.*(N)); (( $#l >= 2 ))\*(Aq:)
670
671 # Find command to search for directory name instead of basename
672   $ print \-rl /**/*~^*/path(|/*)
673   # or \- without Zsh
674   $ find / | grep \-e /path/ \-e \*(Aq/path$\*(Aq
675
676 # Print he path of the directories holding the ten biggest C regular files
677 # in the current directory and subdirectories\&.
678   $ print \-rl \-\- **/*\&.c(D\&.OL[1,10]:h) | sort \-u
679
680 # Find files with size == 0 and send a mail
681   $ files=(**/*(ND\&.L0m+0m\-2))
682   > (( $#files > 0 )) && print \-rl \-\- $files | \e
683     mailx \-s "empty files" foo@bar\&.tdl
684
685 # recursive chmod
686   $ chmod 700 **/(\&.) # Only files
687   $ chmod 700 **/(/) # Only directories
688
689 # print out all of the files in that directory in 2 columns
690   $ print \-rC2 \-\- ${1:[\&.\&.\&.]}/*(D:t)
691 #            ^\- number ob columns
692 # or \- if you feel concerned about special characters \- use
693   $ list=(${1:[\&.\&.\&.]}/*(ND:t))
694   $ (($#list)) && print \-rC2 \-\- ${(V)list}
695
696 # Search all files in /home/*/*\-mail/ with a setting ``chmod \-s\*(Aq\*(Aq flag
697 # (recursive, include  dotfiles) remove the setgid/setuid flag and print
698 # a message
699   $ chmod \-s /home/*/*\-mail(DNs,S) /home/*/*\-mail/**/*(DNs,S))
700 # or with a small script
701   $ for file (/home/*/*\-mail(DNs,S) /home/*/*\-mail/**/*(DNs,S)) {
702   >    print \-r \-\- $file
703   >    chmod \-s $file && print \-r fixed $file
704   > }
705 # or use ``zargs\*(Aq\*(Aq (require autoload zargs) prevent the arg list too
706 # long error
707   $ zargs /home/*/*\-mail(DNs,S) /home/*/*\-mail/**/*(DNs,S)) \-\- chmod \-s
708
709 # List files beginning at `foo23\*(Aq upwards (foo23, foo24, foo25, \&.\&.)
710   $ ls \-l foo<23\->
711
712 # get all files that begin with the date strings from June 4 through
713 # June 9 of 2004
714   $ ls \-l 200406{04\&.\&.10}*(N)
715 # or if they are of the form 200406XX (require ``setopt extended_glob\*(Aq\*(Aq
716   $ ls \-l 200306<4\-10>\&.*
717
718 # remove spaces from filenames
719   $ for a in \&./**/*\e *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
720
721 # Show only all *\&.c and *\&.h \- Files
722   $ ls \-l *\&.(c|h)
723
724 # Show only all *\&.c \- files and ignore `foo\&.c\*(Aq
725   $ ls *\&.c~foo\&.c
726
727 # show data to *really* binary format
728   $ zsh \-ec \*(Aqwhile {} {printf %\&.8x $n;repeat 8 \e
729   > {read \-ku0 a printf \e %\&.8d $(([##2]#a))};print;((n+=8))}\*(Aq < binary
730
731 # Show only world\-readable files
732   $ ls \-l *(R)
733
734 # List files in the current directory are not writable by the owner
735   $ print \-l ~/*(ND\&.^w)
736
737 # find and delete the files which are older than a given parameter
738 # (seconds/minutes/hours)
739   # deletes all regular file in /Dir that are older than 3 hours
740    $ rm \-f /Dir/**/*(\&.mh+3)
741   # deletes all symlinks in /Dir that are older than 3 minutes
742    $ rm \-f /Dir/**/*(@mm+3)
743   # deletes all non dirs in /Dir that are older than 30 seconds
744    $ rm \-f /Dir/**/*(ms+30^/)
745   # deletes all folders, sub\-folders and files older than one hour
746    $ rm \&./**/*(\&.Dmh+1,\&.DL0)
747   # deletes all files more than 6 hours old
748    $ rm \-f **/*(mh+6)
749   # removes all files but the ten newer ones (delete all but last 10
750   # files in a directory)
751    $ rm \&./*(Om[1,\-11])
752  Note: If you get a arg list too long, you use the builtin rm\&. For
753        example:
754    $ zmodload zsh/files ; rm \-f **/*(mh+6)
755   or use the zargs function:
756    $ autoload zargs ; zargs **/*(mh+6) \-\- rm \-f
757
758 # A User\*(Aqs Guide to the Z\-Shell /5\&.9: Filename Generation and Pattern
759 # Matching find all files in all subdirectories, searching recursively,
760 # which have a given name, case insensitive, are at least 50 KB large,
761 # no more than a week old and owned by the root user, and allowing up
762 # to a single error in the spelling of the name\&. In fact, the required
763 # expression looks like this:
764   $ ls **/(#ia1)name(LK+50mw\-1u0)
765
766 # Change the UID from 102 to 666
767   $ chown 666 **/*(u102)
768
769 # List all files which have not been updated since last 10 hours
770   $ print \-rl \-\- *(Dmh+10^/)
771
772 # delete only the oldest file in a directory
773   $ rm \&./*filename*(Om[1])
774
775 # Sort the output from `ls \-l\*(Aq by file size
776   $ ls \-fld *(OL)
777
778 # find most recent file in a directory
779   $ setopt dotglob ; print directory/**/*(om[1])
780
781 # Show only empty files which nor `group\*(Aq or `world writable\*(Aq
782   $ ls *(L0f\&.go\-w\&.)
783
784 # Find \- and list \- the ten newest files in directories and subdirs\&.
785 # (recursive)
786   $ print \-rl \-\- **/*(Dom[1,10])
787
788 # Print only 5 lines by "ls" command (like ``ls \-laS | head \-n 5\*(Aq\*(Aq)\&.
789   $ ls \-fl *(DOL[1,5])
790
791 # Display the 5\-10 last modified files\&.
792   $ print \-rl \-\- /path/to/dir/**/*(D\&.om[5,10])
793
794 # Find all files without a valid owner\&.
795   $ chmod someuser /**/*(D^u:${(j\&.:u:\&.)${(f)"$(</etc/passwd)"}%%:*}:)
796
797 # Find all the empty directories in a tree\&.
798   $ for f in ***/*(/l2); do foo=($f/*(N)); [[ \-z $foo ]] && print $f; done
799 # Note:Since Zsh 4\&.2\&.1 the glob qualifier F indicates a non\-empty directory\&.
800 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all
801 # subdirectories with no entries\&.
802   $ ls \-ld *(/^F)
803
804 # Remove empty directories afterwards\&.
805   $ rmdir \&./**/*(/od) 2> /dev/null
806
807 # Show only files which are owned by group `users\*(Aq\&.
808   $ ls \-l *(G[users])
809 .fi
810 .if n \{\
811 .RE
812 .\}
813 .SS "Modifiers usage"
814 .sp
815 Modifiers are a powerful mechanism that let you modify the results returned by parameter, filename and history expansion\&. See zshexpn(1) for details\&.
816 .sp
817 .if n \{\
818 .RS 4
819 .\}
820 .nf
821 # NOTE: Zsh 4\&.3\&.4 needed!
822   $ autoload \-U age
823 # files modified today
824   $ print *(e:age today now:)
825 # files modified since 5 pm
826   $ print *(e\-age 17:00 now\-)
827 # \&.\&.\&. since 5 o\*(Aqclock yesterda
828   $ print *(e\-age yesterday,17:00 now\-)
829 # \&.\&.\&. from last Christmas before today
830   $ print *(e\-age 2006/12/25 today\-)
831 # \&.\&.\&. before yesterday
832   $ print *(e\-age 1970/01/01 yesterday\-)
833 # all files modified between the start of those dates
834   $ print *(e:age 2006/10/04 2006/10/09:)
835 # all files modified on that date
836   $ print *(e:age 2006/10/04:)
837 # Supply times\&.
838   $ print *(e\-age 2006/10/04:10:15 2006/10/04:10:45\-)
839
840 # Remove a trailing pathname component, leaving the head\&. This works like
841 # `dirname\*(Aq\&.
842   $ echo =ls(:h)
843   /bin
844
845 # Remove all leading pathname components, leaving the tail\&. This works
846 # like `basename\*(Aq\&.
847   $ echo =ls(:t)
848   ls
849
850 # Remove the suffix from each file (*\&.sh in this example)
851    $f:e is $f file extension
852    :h \-\-> head (dirname)
853    :t \-\-> tail (basename)
854    :r \-\-> rest (extension removed)
855   $ for f (*\&.sh) mv $f $f:r
856
857 # Remove a filename extension of the form `\&.xxx\*(Aq, leaving the root name\&.
858   $ echo $PWD
859   /usr/src/linux
860   $ echo $PWD:t
861   linux
862
863 # Remove all but the extension\&.
864   $ foo=23\&.42
865   $ echo $foo
866   23\&.42
867   $ echo $foo:e
868   42
869
870 # Print the new command but do not execute it\&. Only works with history
871 # expansion\&.
872   $ echo =ls(:h)
873   /bin
874   $ !echo:p
875   $ echo =ls(:h)
876
877 # Quote the substituted words, escaping further substitutions\&.
878   $ bar="23\*(Aq42"
879   $ echo $bar
880   23\*(Aq42
881   $ echo $bar:q
882   23\e\*(Aq42
883
884 # Convert the words to all lowercase\&.
885   $ bar=FOOBAR
886   $ echo $bar
887   FOOBAR
888   $ echo $bar:l
889   foobar
890
891 # Convert the words to all uppercase\&.
892   $ bar=foobar
893   $ echo $bar
894   foobar
895   $ echo $bar:u
896   FOOBAR
897
898 # convert 1st char of a word to uppercase
899   $ foo="one two three four"
900   $ print \-r \-\- "${(C)foo}"
901   One Two Three Four
902 .fi
903 .if n \{\
904 .RE
905 .\}
906 .SS "Redirection\-Examples"
907 .sp
908 See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))
909 .sp
910 .if n \{\
911 .RS 4
912 .\}
913 .nf
914 # Append `exit 1\*(Aq at the end of all *\&.sh \- files
915   $ echo "exit 1" >> *\&.sh
916
917 # adding files to foobar\&.tar\&.gz
918   $ eval set =(gunzip < foobar\&.tar\&.gz) \*(Aq
919      tar rf $1 additional\&.txt &&gzip < $1 > foobar\&.tar\&.gz\*(Aq
920
921 # Redirect output to a file AND display on screen
922   $ foobar >&1 > file1 > file2 > \&.\&.
923
924 # pipe single output to multiple inputs
925   $ zcat foobar\&.Z >> (gzip \-9 > file1\&.gz) \e
926       >> (bzip2 \-9 > file1\&.bz2) \e
927       >> (acb \-\-best > file1\&.acb)
928
929 # Append /etc/services at the end of file `foo\*(Aq and `bar\*(Aq
930   $ cat /etc/services >> foo >> bar
931
932 # Pipe STDERR
933   $ echo An error >&2 2>&1 | sed \-e \*(Aqs/A/I/\*(Aq
934
935 # send standard output of one process to standard input of several processes
936 # in the pipeline
937   $ setopt multios
938   $ process1 > >(process1) > >(process2)
939
940 # initializing a variable and simultaneously keeping terminal output
941   $ setopt multios
942   $ { a=$(command >&1 >& 3 3 > &\- 2>&1);} 3>&1
943
944 # redirect stderr two times
945   $ setopt multios ; program 2> file2 > file1 2>&1
946
947 # Duplicating stdout and stderr to a logfile
948   $ exec 3>&1 > logfile 2>&2 2>&1 >&3 3>&\-
949
950 # redirect stderr (only) to a file and to orig\&. stderr:
951   $ command 2>&2 2>stderr
952 # redirect stderr and stdout to separate files and both to orig\&. stdout:
953   $ command 2>&1 1>&1 2>stderr 1>stdout
954 # redirect stderr and stdout to separate files and stdout to orig\&. stdout
955 # AND stderr to orig\&. stderr:
956   $ command 2>&2 1>&1 2>stderr 1>stdout
957
958 # More fun with STDERR ;)
959   $ \&./my\-script\&.sh 2> >(grep \-v moron >error\&.log)|process\-output >output\&.log
960   $  echo "Thats STDOUT" >>(sed \*(Aqs/stdout/another example/\*(Aq > foobar)
961 .fi
962 .if n \{\
963 .RE
964 .\}
965 .SS "ZMV\-Examples (require autoload zmv)"
966 .sp
967 \fBNote:\fR \fI\-n\fR means no execution (just print what would happen)\&. At
968 .sp
969 .if n \{\
970 .RS 4
971 .\}
972 .nf
973 # Remove illegal characters in a fat32 file system\&. Illegal characters are
974 #   / :  ;  *  ?  "  <  >  |
975 # NOTE: ``\-Q\*(Aq\*(Aq and (D) is to include hidden files\&.
976   $ unwanted=\*(Aq[:;*?\e"<>|]\*(Aq
977   $ zmv \-Q "(**/)(*$~unwanted*)(D)" \*(Aq$1${2//$~unwanted/}\*(Aq
978
979 # Changing part of a filename (i\&. e\&. "file\-hell\&.name" \-> "file\-heaven\&.name")
980   $ zmv \*(Aq(*)hell(*)\*(Aq \*(Aq${1}heaven${2}\*(Aq
981   # or
982   $ zmv \*(Aq*\*(Aq \*(Aq$f:s/hell/heaven/\*(Aq
983
984 # remove round bracket within filenames
985 # i\&. e\&. foo\-(bar)\&.avi \-> foo\-bar\&.avi
986   $ zmv \*(Aq*\*(Aq \*(Aq${f//[()]/}\*(Aq
987
988 # serially all files (foo\&.foo > 1\&.foo, fnord\&.foo > 2\&.foo, \&.\&.)
989   $ autoload zmv
990   $ ls *
991   1\&.c  asd\&.foo  bla\&.foo  fnord\&.foo  foo\&.fnord  foo\&.foo
992   $ c=1 zmv \*(Aq*\&.foo\*(Aq \*(Aq$((c++))\&.foo\*(Aq
993   $ ls *
994   1\&.c  1\&.foo  2\&.foo  3\&.foo  4\&.foo  foo\&.fnord
995
996 # Rename "file\&.with\&.many\&.dots\&.txt" by substituting dots (exept for the last
997 # one!) with a space
998   $ touch {1\&.\&.20}\-file\&.with\&.many\&.dots\&.txt
999   $ zmv \*(Aq(*\&.*)(\&.*)\*(Aq \*(Aq${1//\&./ }$2\*(Aq
1000
1001 # Remove the first 4 chars from a filename
1002   $ zmv \-n \*(Aq*\*(Aq \*(Aq$f[5,\-1]\*(Aq # NOTE: The "5" is NOT a mistake in writing!
1003
1004 # Rename names of all files under the current Dir to lower case, but keep
1005 # dirnames as\-is\&.
1006   $ zmv \-Qv \*(Aq(**/)(*)(\&.D)\*(Aq \*(Aq$1${(L)2}\*(Aq
1007
1008 # replace all 4th character, which is "1",  with "2" and so on
1009   $ autoload \-U zmv
1010   $ zmv \*(Aq(???)1(???[1\-4]\&.txt)\*(Aq \*(Aq${1}2${2}\*(Aq
1011
1012 # Remove the first 15 characters from a string
1013   $ touch 111111111111111{a\-z}
1014   $ autoload zmv
1015   $ zmv \*(Aq*\*(Aq \*(Aq$f[16,\-1]\*(Aq
1016
1017 # Replace spaces (any number of them) with a single dash in file names
1018   $ autload zmv
1019   $ zmv \-n \*(Aq(**/)(* *)\*(Aq \*(Aq$1${2//( #\-## #| ##)/\-}\*(Aq
1020   # or \- with Bash
1021   $ find \&. \-depth \-name \*(Aq* *\*(Aq \-exec bash \-c \*(Aq
1022   > shopt \-s extglob
1023   > file=$1
1024   > dir=${file%/*}
1025   > name=${file##*/}
1026   > newname=${name//*([ \-]) *([ \-])/\-}
1027   > mv \-i \-\- "$file" "$Dir/$newname"\*(Aq {} {} \e;
1028
1029 # Clean up file names and remove special characters
1030   $ autoload zmv
1031   $ zmv \-n \*(Aq(**/)(*)\*(Aq \*(Aq$1${2//[^A\-Za\-z0\-9\&._]/_}\*(Aq
1032
1033 # Add *\&.py to a bunch of python scripts in a directory (some of them end
1034 # in *\&.py and give them all a proper extension
1035   $ autoload zmv
1036   $ zmv \-n \*(Aq(**/)(con*)(#qe,file $REPLY | grep "python script",)\*(Aq \*(Aq$1$2\&.py\*(Aq
1037
1038 # lowercase all extensions (i\&. e\&. *\&.JPG) incl\&. subfolders
1039   $ autoload zmv
1040   $ zmv \*(Aq(**/)(*)\&.(#i)jpg\*(Aq \*(Aq$1$2\&.jpg\*(Aq
1041   # Or \- without Zsh
1042   $ find Dir \-name \*(Aq*\&.[jJ][pP][gG]\*(Aq \-print | while read f
1043   > do
1044   >      case $f in
1045   >       *\&.jpg) ;
1046   >       *) mv "$f" "${f%\&.*}\&.jpg" ;
1047   >       esac
1048   > done
1049
1050 # remove leading zeros from file extension
1051   $ autoload zmv
1052   $ ls
1053   filename\&.001  filename\&.003  filename\&.005  filename\&.007  filename\&.009
1054   filename\&.002  filename\&.004  filename\&.006  filename\&.008  filename\&.010
1055   $ zmv \*(Aq(filename\&.)0##(?*)\*(Aq \*(Aq$1$2\*(Aq
1056   $ ls
1057   filename\&.1  filename\&.10  filename\&.2  filename\&.3  filename\&.4  filename\&.5 \&.\&.
1058
1059 # renumber files\&.
1060   $ autoload zmv
1061   $ ls *
1062   foo_10\&.jpg  foo_2\&.jpg  foo_3\&.jpg  foo_4\&.jpg  foo_5\&.jpg  foo_6\&.jpg \&.\&.
1063   $ zmv \-fQ \*(Aqfoo_(<0\->)\&.jpg(\&.nOn)\*(Aq \*(Aqfoo_$(($1 + 1))\&.jpg\*(Aq
1064   $ ls *
1065   foo_10\&.jpg  foo_11\&.jpg  foo_3\&.jpg  foo_4\&.jpg  foo_5\&.jpg  \&.\&.\&.
1066
1067 # adding leading zeros to a filename (1\&.jpg \-> 001\&.jpg, \&.\&.
1068   $ autoload zmv
1069   $ zmv \*(Aq(<1\->)\&.jpg\*(Aq \*(Aq${(l:3::0:)1}\&.jpg\*(Aq
1070
1071 # See above, but now only files with a filename >= 30 chars
1072   $ autoload zmv
1073   $ c=1 zmv "${(l:30\-4::?:)}*\&.foo" \*(Aq$((c++))\&.foo\*(Aq
1074
1075 # Replace spaces in filenames with a underline
1076   $ autoload zmv
1077   $ zmv \*(Aq* *\*(Aq \*(Aq$f:gs/ /_\*(Aq
1078
1079 # Change the suffix from *\&.sh to *\&.pl
1080   $ autoload zmv
1081   $ zmv \-W \*(Aq*\&.sh\*(Aq \*(Aq*\&.pl\*(Aq
1082
1083 # Add a ""\&.txt" extension to all the files within ${HOME}
1084   # ``\-\&.\*(Aq\*(Aq is to only rename regular files or symlinks to regular files,
1085   # ``D\*(Aq\*(Aq is to also rename hidden files (dotfiles))
1086   $ autoload zmv
1087   $ zmv \-Q \*(Aq/home/**/*(D\-\&.)\*(Aq \*(Aq$f\&.txt\*(Aq
1088   # Or to only rename files that don\*(Aqt have an extension:
1089   $ zmv \-Q \*(Aq/home/**/^?*\&.*(D\-\&.)\*(Aq \*(Aq$f\&.txt\*(Aq
1090
1091 # Recursively change filenames with characters ? [ ] / = + < > ; : " , \- *
1092   $ autoload zmv
1093   $ chars=\*(Aq[][?=+<>;",*\-]\*(Aq
1094   $ zmv \*(Aq(**/)(*)\*(Aq \*(Aq$1${2//$~chars/%}\*(Aq
1095
1096 # Removing single quote from filenames (recursively)
1097   $ autoload zmv
1098   $ zmv \-Q "(**/)(*\*(Aq*)(D)" "\e$1\e${2//\*(Aq/}"
1099
1100 # When a new file arrives (named file\&.txt) rename all files in order to
1101 # get (e\&. g\&. file119\&.txt becomes file120\&.txt, file118\&.txt becomes
1102 # file119\&.txt and so on ending with file\&.txt becoming file1\&.txt
1103   $ autoload zmv
1104   $ zmv \-fQ \*(Aqfile([0\-9]##)\&.txt(On)\*(Aq \*(Aqfile$(($1 + 1))\&.txt\*(Aq
1105
1106 # lowercase/uppercase all files/directories
1107   $ autoload zmv
1108   $ zmv \*(Aq(*)\*(Aq \*(Aq${(L)1}\*(Aq # lowercase
1109   $ zmv \*(Aq(*)\*(Aq \*(Aq${(U)1}\*(Aq # uppercase
1110
1111 # Remove the suffix *\&.c from all C\-Files
1112   $ autoload zmv
1113   $ zmv \*(Aq(*)\&.c\*(Aq \*(Aq$1\*(Aq
1114
1115 # Uppercase only the first letter of all *\&.mp3 \- files
1116   $ autoload zmv
1117   $ zmv \*(Aq([a\-z])(*)\&.mp3\*(Aq \*(Aq${(C)1}$2\&.mp3\*(Aq
1118
1119 # Copy the target `README\*(Aq in same directory as each `Makefile\*(Aq
1120   $ autoload zmv
1121   $ zmv \-C \*(Aq(**/)Makefile\*(Aq \*(Aq${1}README\*(Aq
1122
1123 # Removing single quote from filenames (recursively)
1124   $ autoload zmv
1125   $ zmv \-Q "(**/)(*\*(Aq*)(D)" "\e$1\e${2//\*(Aq/}"
1126
1127 # Rename pic1\&.jpg, pic2\&.jpg, \&.\&. to pic0001\&.jpg, pic0002\&.jpg, \&.\&.
1128   $ autoload zmv
1129   $ zmv \*(Aqpic(*)\&.jpg\*(Aq \*(Aqpic${(l:4::0:)1}\&.jpg\*(Aq
1130   $ zmv \*(Aq(**/)pic(*)\&.jpg\*(Aq \*(Aq$1/pic${(l:4::0:)2}\&.jpg\*(Aq # recursively
1131 .fi
1132 .if n \{\
1133 .RE
1134 .\}
1135 .SS "Module\-Examples"
1136 .sp
1137 Please read zshmodules(1) first!
1138 .sp
1139 .it 1 an-trap
1140 .nr an-no-space-flag 1
1141 .nr an-break-flag 1
1142 .br
1143 .ps +1
1144 \fBzsh/pcre (require zmodload zsh/pcre)\fR
1145 .RS 4
1146 .sp
1147 .if n \{\
1148 .RS 4
1149 .\}
1150 .nf
1151 # Copy files of a certain period (date indicated in the filenames)
1152   $ zmodload zsh/pcre
1153   $ ls \-d \-\- *(e:\*(Aq[[ $REPLY \-pcre\-match pcre\-regexp ]]\*(Aq:)
1154   # or
1155   $ m() { [[ $1 \-pcre\-match pcre\-regexp ]] }
1156   $ ls \-d \-\- *(+m)
1157 .fi
1158 .if n \{\
1159 .RE
1160 .\}
1161 .RE
1162 .sp
1163 .it 1 an-trap
1164 .nr an-no-space-flag 1
1165 .nr an-break-flag 1
1166 .br
1167 .ps +1
1168 \fBzsh/clone (require zmodload zsh/clone)\fR
1169 .RS 4
1170 .sp
1171 .if n \{\
1172 .RS 4
1173 .\}
1174 .nf
1175 # Creates a forked instance of the current shell ($! is set to zero) and
1176 # execute ``command\*(Aq\*(Aq on /dev/tty8 (for this example)\&.
1177   $ zmodload zsh/clone
1178   $ clone /dev/tty8 && (($! == 0)) && exec command
1179 .fi
1180 .if n \{\
1181 .RE
1182 .\}
1183 .RE
1184 .sp
1185 .it 1 an-trap
1186 .nr an-no-space-flag 1
1187 .nr an-break-flag 1
1188 .br
1189 .ps +1
1190 \fBzsh/datetime (require zmodload zsh/datetime)\fR
1191 .RS 4
1192 .sp
1193 .if n \{\
1194 .RS 4
1195 .\}
1196 .nf
1197   $ zmodload zsh/datetime
1198   $ alias datereplacement=\*(Aqstrftime "%Y\-%m\-%d" $EPOCHSECONDS\*(Aq
1199   $ export DATE=`datereplacement`
1200   $ echo $DATE
1201
1202 #  strip date from filename
1203   $ $ zmodload zsh/datetime
1204   $ setopt extendedglob
1205   $ touch aaa_bbb_20041212_c\&.dat eee_fff_20051019_g\&.dat
1206   $ strftime \-s pattern \e
1207     \*(Aq???_???_<0\-%Y%m%d>_?\&.dat\*(Aq $((EPOCHSECONDS \- 365 * 24 * 60 * 60 / 2))
1208   $ print \-rl \-\- $~pattern
1209   aaa_bbb_20041212_c\&.dat
1210   $ print \-rl \-\- $pattern
1211   ???_???_<0\-20050815>_?\&.dat
1212
1213 # Search files size == 0, to be based on the file name containing a date
1214 # rather than the "last modified" date of the file
1215   $ zmodload \-i zsh/datetime
1216   $ strftime \-s file "abc_de_%m%d%Y\&.dat" $((EPOCHSECONDS \- 24 * 60 * 60 ))
1217   $ files=(**/$file(N\&.L0))
1218   $ (( $#files > 0 )) && print \-rl \-\- $files | \e
1219     mailx \-s "empty files"  foo@bar\&.tdl
1220 .fi
1221 .if n \{\
1222 .RE
1223 .\}
1224 .RE
1225 .sp
1226 .it 1 an-trap
1227 .nr an-no-space-flag 1
1228 .nr an-break-flag 1
1229 .br
1230 .ps +1
1231 \fBzsh/stat (require zmodload zsh/stat)\fR
1232 .RS 4
1233 .sp
1234 .if n \{\
1235 .RS 4
1236 .\}
1237 .nf
1238 # test if a symbolic link links to a certain file
1239   $ zmodload \-i zsh/stat
1240   $ ! stat \-LH s foo\&.ln || [[ $s[link] != "foo\&.exe" ]] || ln \-sf foo\&.exe foo\&.ln
1241
1242 # comparing file dates
1243   $ zmodload zsh/stat
1244   $ file1=foo
1245   $ file2=bar
1246   $ touch bar & sleep 5 & touch foo
1247   $ echo $file1 is $(($(stat +mtime $file2) \- \e
1248     $(stat +mtime $file1))) seconds older than $file2\&.
1249   bar is 5 seconds older than foo
1250
1251 # list the files of a disk smaller than some other file
1252   $ zmodload zsh/stat
1253   $ stat \-A max +size some\-other\-file
1254   $ print \-rl \&./**/*(D\&.L\-$max)
1255
1256 # List the top 100 biggest files in a disk
1257   $ zmodload zsh/stat
1258   $ ls \-fld \&./**/*(d`stat +device \&.`OL[1,100])
1259
1260 # Get only the user name and the file names from (like
1261 # ls \-l * | awk \*(Aq{print $3" " $8}\*(Aq)
1262   $ zmodload zsh/stat
1263   $ for file; do
1264   >   stat \-sA user +uid \-\- "$file" &&
1265   >     print \-r \-\- "$user" "$file"
1266   > done
1267
1268 # get the difference between actual bytes of file and allocated bytes of file
1269   $ zmodload zsh/stat
1270   $ print $(($(stat +block \-\- file) * 512 \- $(stat +size \-\- file)))
1271
1272 # Find largest file
1273 # ``D\*(Aq\*(Aq  : to include dot files (d lowercase is for device)
1274 # ``O\*(Aq\*(Aq  : reverse Ordered (o lowercase for non\-reverse order)
1275 # ``L\*(Aq\*(Aq  : by file Length (l is for number of links)
1276 # ``[1]\*(Aq\*(Aq: return only first one
1277   $ zmodload zsh/stat
1278   $ stat +size \&./*(DOL[1])
1279
1280 # file size in bytes
1281   $ zmodload zsh/stat
1282   $ stat \-L +size ~/\&.zshrc
1283   4707
1284
1285 # Delete files in a directory that hasn\*(Aqt been accessed in the last ten days
1286 # and send ONE mail to the owner of the files informing him/her of the files\*(Aq
1287 # deletion\&.
1288   $ zmodload zsh/stat zsh/files
1289   $ typeset \-A f; f=()
1290   $ rm \-f /path/**/*(\&.a+10e{\*(Aqstat \-sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"\*(Aq})
1291   $ for user (${(k)f}) {print \-rn $f[$user]|mailx \-s "\&.\&.\&." $user}
1292
1293 # Get a "ls \-l" on all the files in the tree that are younger than a
1294 # specified age
1295   $ zmodload zsh/stat
1296   $ for d (\&. \&./**/*(N/m\-2))
1297   >   print \-r \-\- $\*(Aq\en\*(Aq$d: && cd $d && {
1298   >      for f (*(Nm\-2om))
1299   >   stat \-F \*(Aq%b %d %H:%M\*(Aq \-LsAs \-\- $f &&
1300   >   print \-r \-\- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \e
1301   >   ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+\-> $s[14]}
1302   >   cd ~\-
1303   > }
1304
1305 # get file creation date
1306   $ zmodload zsh/stat
1307   $ stat \-F \*(Aq%d %m %Y\*(Aq +mtime ~/\&.zshrc
1308   30 06 2004
1309   $ stat \-F \*(Aq%D\*(Aq +mtime ~/\&.zshrc
1310   06/30/04
1311 .fi
1312 .if n \{\
1313 .RE
1314 .\}
1315 .RE
1316 .sp
1317 .it 1 an-trap
1318 .nr an-no-space-flag 1
1319 .nr an-break-flag 1
1320 .br
1321 .ps +1
1322 \fBzsh/files (require zmodload zsh/files)\fR
1323 .RS 4
1324 .sp
1325 .if n \{\
1326 .RS 4
1327 .\}
1328 .nf
1329 # search a directory for files containing a certain string then copy those
1330 # files to another directory\&.
1331   $ zmodload zsh/files
1332   $ IFS=$\*(Aq\e0\*(Aq
1333   $ cp $(grep \-lZr foobar \&.) otherdirectory
1334 .fi
1335 .if n \{\
1336 .RE
1337 .\}
1338 .RE
1339 .sp
1340 .it 1 an-trap
1341 .nr an-no-space-flag 1
1342 .nr an-break-flag 1
1343 .br
1344 .ps +1
1345 \fBzsh/mapfile (require zmodload zsh/mapfile)\fR
1346 .RS 4
1347 .sp
1348 .if n \{\
1349 .RS 4
1350 .\}
1351 .nf
1352 # grepping for two patterns
1353   $ zmodload zsh/mapfile
1354   $ pattern1="foo"
1355   $ pattern2="bar foo"
1356   $ print \-l \&./**/*(DN\&.e{\*(Aqz=$mapfile[$REPLY] && [[ $z = *$pattern1* && \e
1357     $z = *$pattern2* ]]\*(Aq})
1358 # or a solution in combination with zsh/pcre
1359   $ zmodload \-i zsh/mapfile zsh/pcre
1360   $ pattern1="foo"
1361   $ pattern2="bar foo"
1362   $ pcre_compile "(?s)(?=\&.*?$pattern1)\&.*?$pattern2"
1363   $ pcre_study
1364   $ print \-l \&./**/*(DN\&.e{\*(Aqpcre_match $mapfile[$REPLY]\*(Aq})
1365
1366 # equivalent for ``less /etc/passwd | grep \-v root\*(Aq\*(Aq
1367   $ zmodload zsh/mapfile
1368   $ IFS=$\*(Aq\en\en\*(Aq
1369   $ print \-rl \-\- ${${=mapfile[/etc/passwd]}:#*root*}
1370 # or \- for case insensitive
1371   $ setopt extendedglob
1372   $ print \-rl \-\- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
1373
1374 # If a XML\-file contains stuff like ``<TAGA/>\*(Aq\*(Aq and ``<TAGB/>\*(Aq\*(Aq, number
1375 # this empty tags (ones ending in \*(Aq/>\*(Aq) so if encountered in the same
1376 # order, the preceeding tags would become ``<TAGA/>1</TAGA>\*(Aq\*(Aq and
1377 # ``<TAGB/>2</TAGB>\*(Aq\*(Aq
1378   $ zmodload zsh/mapfile
1379   $ cnt=0
1380   $ apfile[data\&.xml\&.new]=${(S)mapfile[data\&.xml]//\e
1381   > (#im)<TAGA>*<\e/TAGA>/<TAGA>$((++cnt))<\e/TAGA>}
1382
1383 # removing all files in users Maildir/new that contain ``filename="gone\&.src\*(Aq\*(Aq
1384   $ zmodload zsh/{files,mapfile}
1385   $ rm \-f /u1/??/*/Maildir/new/100*(\&.e{\*(Aq[[ $mapfile[$REPLY] == \e
1386     *filename=\e"gone\&.scr\e"* ]]\*(Aq})
1387
1388 # Grep out the Title from a postscript file and append that value to the
1389 # end of the filename
1390   $ autoload \-U zmv
1391   $ zmodload zsh/mapfile
1392   $ zmv \*(Aq(*)\&.ps\*(Aq \*(Aq$1\-${${${mapfile[$f]##*%%Title: }%% *}//[^a\-zA\-Z0\-9_]/}\&.ps\*(Aq
1393 .fi
1394 .if n \{\
1395 .RE
1396 .\}
1397 .RE
1398 .sp
1399 .it 1 an-trap
1400 .nr an-no-space-flag 1
1401 .nr an-break-flag 1
1402 .br
1403 .ps +1
1404 \fBzsh/mathfunc (require zmodload zsh/mathfunc)\fR
1405 .RS 4
1406 .sp
1407 .if n \{\
1408 .RS 4
1409 .\}
1410 .nf
1411 $ zmodload zsh/mathfunc
1412 $ echo $(( sin(1/4\&.0)**2 + cos(1/4\&.0)**2 \- 1 ))
1413   \-1\&.1102230246251565e\-16
1414 $ echo $(( pi = 4\&.0 * atan(1\&.0) ))
1415   3\&.1415926535897931
1416 $ echo $(( f = sin(0\&.3) ))
1417   0\&.29552020666133955
1418 $ print $((1e12 * rand48()))
1419   847909677310\&.23413
1420 $ print $(( rand48(seed) ))
1421   0\&.01043488334700271
1422 .fi
1423 .if n \{\
1424 .RE
1425 .\}
1426 .RE
1427 .sp
1428 .it 1 an-trap
1429 .nr an-no-space-flag 1
1430 .nr an-break-flag 1
1431 .br
1432 .ps +1
1433 \fBzsh/termcap (require zmodload zsh/termcap)\fR
1434 .RS 4
1435 .sp
1436 .if n \{\
1437 .RS 4
1438 .\}
1439 .nf
1440  $ zmodload \-ab zsh/termcap echotc
1441  $ GREEN=`echotc AF 2`
1442  $ YELLOW=`echotc AF 3`
1443  $ RED=`echotc AF 1`
1444  $ BRIGHTRED=`echotc md ; echotc AF 1`
1445  $ print \-l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred
1446 .fi
1447 .if n \{\
1448 .RE
1449 .\}
1450 .RE
1451 .sp
1452 .it 1 an-trap
1453 .nr an-no-space-flag 1
1454 .nr an-break-flag 1
1455 .br
1456 .ps +1
1457 \fBzsh/zpty (require zmodload zsh/zpty)\fR
1458 .RS 4
1459 .sp
1460 .if n \{\
1461 .RS 4
1462 .\}
1463 .nf
1464   $ zmodload zsh/zpty
1465   $ zpty PW passwd $1
1466   $ zpty PW passwd $1
1467 # ``\-r\*(Aq\*(Aq: read the output of the command name\&.
1468 # ``z\*(Aq\*(Aq : Parameter
1469   $ zpty \-r PW z \*(Aq*password:\*(Aq
1470 # send the to command name the given strings as input
1471   $ zpty \-w PW $2
1472   $ zpty \-r PW z \*(Aq*password:\*(Aq
1473   $ zpty \-w PW $2
1474 # The second form, with the \-d option, is used to delete commands
1475 # previously started, by supplying a list of their names\&. If no names
1476 # are given, all commands are deleted\&. Deleting a command causes the HUP
1477 # signal to be sent to the corresponding process\&.
1478   $ zpty \-d PW
1479 .fi
1480 .if n \{\
1481 .RE
1482 .\}
1483 .RE
1484 .sp
1485 .it 1 an-trap
1486 .nr an-no-space-flag 1
1487 .nr an-break-flag 1
1488 .br
1489 .ps +1
1490 \fBzsh/net/socket (require zmodload zsh/net/socket)\fR
1491 .RS 4
1492 .sp
1493 .if n \{\
1494 .RS 4
1495 .\}
1496 .nf
1497 # ``\-l\*(Aq\*(Aq: open a socket listening on filename
1498 # ``\-d\*(Aq\*(Aq: argument will be taken as the target file descriptor for the
1499 #         connection
1500 # ``3\*(Aq\*(Aq : file descriptor\&. See ``A User\*(Aqs Guide to the Z\-Shell\*(Aq\*(Aq
1501 #         (3\&.7\&.2: File descriptors)
1502   $ zmodload zsh/net/socket
1503   $ zsocket \-l \-d 3
1504 # ``\-a\*(Aq\*(Aq: accept an incoming connection to the socket
1505   $ zsocket \-a \-d 4 3
1506   $ zsocket \-a \-d 5 3 # accept a connection
1507   $ echo foobar >&4
1508   $ echo barfoo >&5
1509   $ 4>&\- 5>&\- 3>&
1510 .fi
1511 .if n \{\
1512 .RE
1513 .\}
1514 .RE
1515 .sp
1516 .it 1 an-trap
1517 .nr an-no-space-flag 1
1518 .nr an-break-flag 1
1519 .br
1520 .ps +1
1521 \fBzsh/zftp (require zmodload zsh/zftp)\fR
1522 .RS 4
1523 .sp
1524 .if n \{\
1525 .RS 4
1526 .\}
1527 .nf
1528  $ autoload \-U zfinit
1529  $ zfinit
1530  $ zfparams www\&.example\&.invalid myuserid mypassword
1531  $ zfopen
1532  $ zfcd tips
1533  $ zfls \-l zshtips\&.html
1534  $ zfput zshtips\&.html
1535  $ zfls \-l zshtips\&.html
1536
1537 # Automatically transfer files using FTP with error checking
1538   $ autoload \-U zfinit ; zfinit
1539   $ zftp open host\&.name\&.invalid user passwd || exit
1540   $ zftp get /remote/file > /local/file; r=$?
1541   $ zftp close && exit r
1542
1543 # compress and ftp on the fly
1544   $ autoload \-U zfinit ; zfinit
1545   $ zftp open host\&.name\&.invalid user password
1546   $ zftp get $file | bzip2 > ${file}\&.bz2
1547   $ zftp close
1548
1549 # Recursice ``get\*(Aq\*(Aq
1550   $ autoload \-U zfinit ; zfinit
1551   $ zfanon cr\&.yp\&.to
1552   $ zfcd daemontools
1553   $ for file in `zfls` ; do
1554   >     zfget $file
1555   $ done
1556   $ zfclose
1557
1558 # Upload all regular files in $HOME/foobar (recursive) that are newer than
1559 # two hours to ftp\&.foobar\&.invalid/path/to/upload
1560   $ autoload \-U zfinit ; zfinit
1561   $ zfopen ftp\&.foobar\&.invalid/path/to/upload
1562   $ cd $HOME/foobar
1563   $ zfput \-r **/*(\&.mh\-2)
1564   $ zfclose
1565
1566 # long list of files on a ftp
1567   $ autoload \-U zfinit ; zfinit
1568   $ zfopen some\-host
1569   $ zfcd /some/remote/Dir
1570   $ cd /some/local/Dir
1571 # If the list\&.txt is located on the remote host, change to
1572 # zfget ${(f)"$(zftp get /path/to/remote/list\&.txt)"}
1573   $ zfget ${(f)"$(cat list\&.txt)"}
1574   $ zfclose
1575 .fi
1576 .if n \{\
1577 .RE
1578 .\}
1579 .RE
1580 .sp
1581 .it 1 an-trap
1582 .nr an-no-space-flag 1
1583 .nr an-break-flag 1
1584 .br
1585 .ps +1
1586 \fBzsh/zselect (require zmodload zsh/zselect)\fR
1587 .RS 4
1588 .sp
1589 .if n \{\
1590 .RS 4
1591 .\}
1592 .nf
1593 # It\*(Aqs similar to
1594  ,\-\-\-\-
1595  | $ sg=$(stty \-g)
1596  | $ stty \-icanon min 0 time 50
1597  | $ read yesno
1598  | $ stty "$sg"
1599  | $ case "$yesno" in
1600  | >  yes) command1;;
1601  | >  *) command2;;
1602  | > esac
1603  `\-\-\-\-
1604 $ zmodload zsh/zselect
1605 $ if zselect \-t 500 \-r 0 && read yesno && [ yes = "$yesno" ]; then
1606 >    command1
1607 > else
1608 >    command1
1609 > fi
1610 .fi
1611 .if n \{\
1612 .RE
1613 .\}
1614 .RE
1615 .SH "OPTIONS"
1616 .SS "Navigation options"
1617 .sp
1618 \fBauto_cd\fR (allow one to change to a directory by entering it as a command)\&. \fBauto_pushd\fR (automatically append dirs to the push/pop list) pushd_ignore_dups (and don\(cqt duplicate them)\&.
1619 .SS "Misc"
1620 .sp
1621 \fBno_hup\fR (don\(cqt send HUP signal to background jobs when exiting ZSH)\&. \fBprint_exit_value\fR (show a message with the exit code when a command returns with a non\-zero exit code)
1622 .sp
1623 .it 1 an-trap
1624 .nr an-no-space-flag 1
1625 .nr an-break-flag 1
1626 .br
1627 .ps +1
1628 \fBHistory options\fR
1629 .RS 4
1630 .sp
1631 \fBhist_verify\fR (let the user edit the command line after history expansion (e\&.g\&. !ls) instead of immediately running it) Use the same history file for all sessions : \fBsetopt SHARE_HISTORY\fR
1632 .RE
1633 .sp
1634 .it 1 an-trap
1635 .nr an-no-space-flag 1
1636 .nr an-break-flag 1
1637 .br
1638 .ps +1
1639 \fBPrivacy / Security\fR
1640 .RS 4
1641 .sp
1642 \fBno_clobber\fR (or set \-C; prevent \fI>\fR redirection from truncating the given file if it already exists)
1643 .RE
1644 .sp
1645 .it 1 an-trap
1646 .nr an-no-space-flag 1
1647 .nr an-break-flag 1
1648 .br
1649 .ps +1
1650 \fBSpelling correction\fR
1651 .RS 4
1652 .sp
1653 \fBcorrect\fR (automatically correct the spelling of commands)\&. \fBcorrect_all\fR (automatically correct the spelling of each word on the command line) \fBdvorak\fR (dvorak layout)
1654 .RE
1655 .SH "UNSORTED/MISC"
1656 .sp
1657 Mailpath: simple multiple mailpath:
1658 .sp
1659 .if n \{\
1660 .RS 4
1661 .\}
1662 .nf
1663 mailpath=($HOME/Mail/mbox\*(Aq?new mail in mbox\*(Aq
1664           $HOME/Mail/tux\&.u\-strasbg\*(Aq?new mail in tux\*(Aq
1665           $HOME/Mail/lilo\*(Aq?new mail in lilo\*(Aq
1666           $HOME/Mail/ldap\-fr\*(Aq?new mail in ldap\-fr\*(Aq)
1667 .fi
1668 .if n \{\
1669 .RE
1670 .\}
1671 .sp
1672 Mailpath: dynamic mailpath:
1673 .sp
1674 .if n \{\
1675 .RS 4
1676 .\}
1677 .nf
1678 typeset \-a mailpath
1679 for i in ~/Mail/Lists/*(\&.); do
1680    mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}\&."
1681 done
1682 .fi
1683 .if n \{\
1684 .RE
1685 .\}
1686 .sp
1687 Avoid globbing on special commands:
1688 .sp
1689 .if n \{\
1690 .RS 4
1691 .\}
1692 .nf
1693 for com in alias expr find mattrib mcopy mdir mdel which;
1694 alias $com="noglob $com"
1695 .fi
1696 .if n \{\
1697 .RE
1698 .\}
1699 .sp
1700 For migrating your bashprompt to zsh use the script bash2zshprompt located in the zsh source distribution under \fIMisc\fR\&.
1701 .sp
1702 For migration from (t)csh to zsh use the c2z tool that converts csh aliases and environment and shell variables to zsh\&. It does this by running csh, and having csh report on aliases and variables\&. The script then converts these to zsh startup files\&. It has some issues and usage information that are documented at the top of this script\&.
1703 .sp
1704 Here are functions to set the title and hardstatus of an \fBXTerm\fR or of \fBGNU Screen\fR to \fIzsh\fR and the current directory, respectively, when the prompt is displayed, and to the command name and rest of the command line, respectively, when a command is executed:
1705 .sp
1706 .if n \{\
1707 .RS 4
1708 .\}
1709 .nf
1710 function title {
1711       if [[ $TERM == "screen" ]]; then
1712         # Use these two for GNU Screen:
1713         print \-nR $\*(Aq 33k\*(Aq$1$\*(Aq 33\*(Aq\e
1714         print \-nR $\*(Aq 33]0;\*(Aq$2$\*(Aq\*(Aq
1715       elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
1716         # Use this one instead for XTerms:
1717         print \-nR $\*(Aq 33]0;\*(Aq$*$\*(Aq\*(Aq
1718       fi
1719 }
1720 function precmd { title zsh "$PWD" }
1721 function preexec {
1722     emulate \-L zsh
1723     local \-a cmd; cmd=(${(z)1})
1724     title $cmd[1]:t "$cmd[2,\-1]"
1725 }
1726 .fi
1727 .if n \{\
1728 .RE
1729 .\}
1730 .sp
1731 Put the following line into your ~/\&.screenrc to see this fancy hardstatus:
1732 .sp
1733 .if n \{\
1734 .RS 4
1735 .\}
1736 .nf
1737 caption always "%3n %t%? (%u)%?%?: %h%?"
1738 .fi
1739 .if n \{\
1740 .RE
1741 .\}
1742 .sp
1743 Special variables which are assigned:
1744 .sp
1745 .if n \{\
1746 .RS 4
1747 .\}
1748 .nf
1749 $LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID
1750 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath
1751 .fi
1752 .if n \{\
1753 .RE
1754 .\}
1755 .SH "LINKS"
1756 .PP
1757 Primary site
1758 .RS 4
1759 \fBhttp://www\&.zsh\&.org/\fR
1760 .RE
1761 .PP
1762 Project\-page
1763 .RS 4
1764 \fBhttp://sourceforge\&.net/projects/zsh/\fR
1765 .RE
1766 .PP
1767 Z shell page at sunsite\&.dk
1768 .RS 4
1769 \fBhttp://zsh\&.sunsite\&.dk/\fR
1770 .RE
1771 .PP
1772 From Bash to Z Shell: Conquering the Command Line \- the book
1773 .RS 4
1774 \fBhttp://www\&.bash2zsh\&.com/\fR
1775 .RE
1776 .PP
1777 "Zsh \- die magische Shell" (german book about Zsh) by Sven Guckes and Julius Plenz
1778 .RS 4
1779 \fBhttp://zshbuch\&.org/\fR
1780 .RE
1781 .PP
1782 Mailinglistarchive
1783 .RS 4
1784 \fBhttp://www\&.zsh\&.org/mla/\fR
1785 .RE
1786 .PP
1787 ZSH\-FAQ
1788 .RS 4
1789 \fBhttp://zsh\&.dotsrc\&.org/FAQ/\fR
1790 .RE
1791 .PP
1792 Userguide
1793 .RS 4
1794 \fBhttp://zsh\&.sunsite\&.dk/Guide/\fR
1795 .RE
1796 .PP
1797 ZSH\-Wiki
1798 .RS 4
1799 \fBhttp://zshwiki\&.org/home/\fR
1800 .RE
1801 .PP
1802 A short introduction from BYU
1803 .RS 4
1804 \fBhttp://docs\&.cs\&.byu\&.edu/linux/advanced/zsh\&.html\fR
1805 .RE
1806 .PP
1807 Mouse\-Support ;)
1808 .RS 4
1809 \fBhttp://stchaz\&.free\&.fr/mouse\&.zsh\fR
1810 .RE
1811 .PP
1812 Curtains up: introducing the Z shell
1813 .RS 4
1814 \fBhttp://www\-128\&.ibm\&.com/developerworks/linux/library/l\-z\&.html?dwzone=linux\fR
1815 .RE
1816 .PP
1817 ZSH\-Liebhaberseite (german)
1818 .RS 4
1819 \fBhttp://michael\-prokop\&.at/computer/tools_zsh_liebhaber\&.html\fR
1820 .RE
1821 .PP
1822 ZSH\-Seite von Michael Prokop (german)
1823 .RS 4
1824 \fBhttp://michael\-prokop\&.at/computer/tools_zsh\&.html\fR
1825 .RE
1826 .PP
1827 ZSH Prompt introduction
1828 .RS 4
1829 \fBhttp://aperiodic\&.net/phil/prompt/\fR
1830 .RE
1831 .PP
1832 ft\(cqs zsh configuration
1833 .RS 4
1834 \fBhttp://ft\&.bewatermyfriend\&.org/comp/zsh\&.html\fR
1835 .RE
1836 .PP
1837 Adam\(cqs ZSH page
1838 .RS 4
1839 \fBhttp://www\&.adamspiers\&.org/computing/zsh/\fR
1840 .RE
1841 .PP
1842 Zzappers Best of ZSH Tips
1843 .RS 4
1844 \fBhttp://www\&.rayninfo\&.co\&.uk/tips/zshtips\&.html\fR
1845 .RE
1846 .PP
1847 Zsh Webpage by Christian Schneider
1848 .RS 4
1849 \fBhttp://www\&.strcat\&.de/zsh/\fR
1850 .RE
1851 .PP
1852 The zsh\-lovers webpage
1853 .RS 4
1854 \fBhttp://grml\&.org/zsh/\fR
1855 .RE
1856 .PP
1857 IRC channel
1858 .RS 4
1859 \fB#zsh at irc\&.libera\&.chat\fR
1860 .RE
1861 .PP
1862 The Z shell reference\-card (included in the zsh\-lovers debian\-package)
1863 .RS 4
1864 \fBhttp://www\&.bash2zsh\&.com/zsh_refcard/refcard\&.pdf\fR
1865 .RE
1866 .SH "AUTHORS"
1867 .sp
1868 This manpage was written by Michael Prokop, Christian \fIstrcat\fR Schneider and Matthias Kopfermann\&. But many ideas have been taken from zsh\-geeks e\&.g\&. from the zsh\-mailinglists (zsh\-users and zsh\-workers), google, newsgroups and the zsh\-Wiki\&. Thanks for your cool and incredible tips\&. We learned much from you!
1869 .sp
1870 In alphabetic order:
1871 .sp
1872 .if n \{\
1873 .RS 4
1874 .\}
1875 .nf
1876 Andrew \*(Aqzefram\*(Aq Main  \- http://www\&.fysh\&.org/~zefram/
1877 Barton E\&. Schaefer    \- http://www\&.well\&.com/user/barts/
1878 Matthias Kopfermann   \- http://www\&.infodrom\&.north\&.de/~matthi/
1879 Oliver Kiddle         \- http://people\&.freenet\&.de/opk/
1880 Paul Falstad          \- http://www\&.falstad\&.com/
1881 Peter Stephenson      \- http://homepage\&.ntlworld\&.com/p\&.w\&.stephenson/
1882 Richard Coleman
1883 Stephane Chazelas     \- http://stephane\&.chazelas\&.free\&.fr/
1884 Sven Guckes           \- http://www\&.guckes\&.net/
1885 Sven Wischnowsky      \- http://w9y\&.de/zsh/zshrc
1886 .fi
1887 .if n \{\
1888 .RE
1889 .\}
1890 .SH "SEE ALSO"
1891 .sp
1892 Manpages of zsh:
1893 .sp
1894 .if n \{\
1895 .RS 4
1896 .\}
1897 .nf
1898        zsh          Zsh overview
1899        zshall       Tthe Z shell meta\-man page
1900        zshbuiltins  Zsh built\-in commands
1901        zshcalsys    zsh calendar system
1902        zshcompctl   zsh programmable completion
1903        zshcompsys   Zsh completion system
1904        zshcompwid   Zsh completion widgets
1905        zshcontrib   User contributions to zsh
1906        zshexpn      Zsh expansion and substitution
1907        zshmisc      Anything not fitting into the other sections
1908        zshmodules   Zsh loadable modules
1909        zshoptions   Zsh options
1910        zshparam     Zsh parameters
1911        zshroadmap   Informal introduction to the zsh manual
1912        zshtcpsys    Zsh tcp system
1913        zshzle       Zsh command line editing
1914        zshzftpsys   Zsh built\-in FTP client
1915        zshall       Meta\-man page containing all of the above
1916 .fi
1917 .if n \{\
1918 .RE
1919 .\}
1920 .sp
1921 Note: especially \fIman zshcontrib\fR covers very useful topics! Book: \fBFrom Bash to Z Shell\fR by Oliver Kiddle, Jerry Peck and Peter Stephenson\&. \fBISBN: 1590593766\fR\&. \- \fBbash2zsh\&.com\fR Also take a look at the section \fBLINKS\fR in this manpage\&.
1922 .SH "BUGS"
1923 .sp
1924 Probably\&. This manpage might be never complete\&. So please report bugs, feedback and suggestions to <zsh\-lovers@michael\-prokop\&.at>\&. Thank you!
1925 .SH "COPYRIGHT"
1926 .sp
1927 Copyright (C) Michael Prokop, Christian Schneider and Matthias Kopfermann\&.