6 zsh-lovers - tips, tricks and examples for the Z shell
14 Whenever we look at the zsh manual we wonder why there are no examples or those
15 simply things in (shell) life. The zsh contains many features, but there was no
16 manpage with some examples (like procmailex(5)). That's why we wrote this
19 Most of the tricks and oneliner come from the mailinglists zsh-users,
20 zsh-workers, google, newsgroups and from ourself. See section *LINKS* for
23 Note: This manpage (zsh-lovers(1)) is *not* an offical part of the Z shell! It's
24 just a just for fun - manpage ;) +
25 For comments, bugreports and feedback take a quick look at the section *BUGS*.
29 This section provides some examples for often needed shellscript-stuff. Notice
30 that you should not use otherwise most examples won't work. +
31 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski
32 (http://www.chodorowski.com/projects/zws/[]):
33 ----------------------------------------------
40 zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help
41 if [[ $? != 0 || "$o_help" != "" ]]; then
42 echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"
50 if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi
52 # now use the function:
54 ----------------------------------------------
58 Available subsections are *Aliases*, *Completion*, *Unsorted/Misc examples*,
59 *(Recursive) Globbing - Examples*, *Modifiers usage*, *Redirection-Examples*,
60 *ZMV-Examples* and *Module-Examples*.
64 Suffix aliases are supported in zsh since version 4.2.0. Some examples:
70 Now pressing return-key after entering 'foobar.tex' starts vim with
71 foobar.tex. Calling a html-file runs browser w3m. 'www.zsh.org' and pressing
72 enter starts w3m with argument www.zsh.org. +
73 Global aliases can be used anywhere in the command line. Example:
74 ----------------------
75 $ alias -g C='| wc -l'
76 $ grep alias ~/.zsh/* C
78 ----------------------
79 Some more or less useful global aliases (choose whether they are useful or not
82 --------------------------------------------------------
84 alias -g ....='../../..'
85 alias -g .....='../../../..'
86 alias -g CA="2>&1 | cat -A"
88 alias -g D="DISPLAY=:0.0"
90 alias -g ED="export DISPLAY=:0.0"
91 alias -g EG='|& egrep'
94 alias -g ELS='|& less -S'
95 alias -g ETL='|& tail -20'
100 alias -g HL='|& head -20'
101 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"
102 alias -g LL="2>&1 | less"
104 alias -g LS='| less -S'
107 alias -g NE="2> /dev/null"
108 alias -g NS='| sort -n'
109 alias -g NUL="> /dev/null 2>&1"
111 alias -g R=' > /c/aaa/tee.txt '
112 alias -g RNS='| sort -nr'
114 alias -g TL='| tail -20'
116 alias -g US='| sort -u'
117 alias -g VM=/var/log/messages
118 alias -g X0G='| xargs -0 egrep'
119 alias -g X0='| xargs -0'
120 alias -g XG='| xargs egrep'
122 --------------------------------------------------------
126 See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old
127 style of zsh programmable completion, zshcompsys is the new completion
128 system, zshcompwid are the zsh completion widgets.
130 Some functions, like _apt and _dpkg, are very slow. You can use a cache
131 in order to proxy the list of results (like the list of available
132 debian packages) Use a cache:
133 ---------------------------------------------------------------------------------------------------
134 zstyle ':completion:*' use-cache on
135 zstyle ':completion:*' cache-path ~/.zsh/cache
136 ---------------------------------------------------------------------------------------------------
138 Prevent CVS files/directories from being completed:
139 ---------------------------------------------------------------------------------------------------
140 zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
141 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
142 ---------------------------------------------------------------------------------------------------
144 Fuzzy matching of completions for when you mistype them:
145 ---------------------------------------------------------------------------------------------------
146 zstyle ':completion:*' completer _complete _match _approximate
147 zstyle ':completion:*:match:*' original only
148 zstyle ':completion:*:approximate:*' max-errors 1 numeric
149 ---------------------------------------------------------------------------------------------------
151 And if you want the number of errors allowed by _approximate to
152 increase with the length of what you have typed so far:
153 ---------------------------------------------------------------------------------------------------
154 zstyle -e ':completion:*:approximate:*' \
155 max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
156 ---------------------------------------------------------------------------------------------------
158 Ignore completion functions for commands you don't have:
159 ---------------------------------------------------------------------------------------------------
160 zstyle ':completion:*:functions' ignored-patterns '_*'
161 ---------------------------------------------------------------------------------------------------
163 With helper functions like:
164 ---------------------------------------------------------------------------------------------------
165 xdvi() { command xdvi ${*:-*.dvi(om[1])} }
166 ---------------------------------------------------------------------------------------------------
168 you can avoid having to complete at all in many cases, but if you do,
169 you might want to fall into menu selection immediately and to have the
170 words sorted by time:
171 ---------------------------------------------------------------------------------------------------
172 zstyle ':completion:*:*:xdvi:*' menu yes select
173 zstyle ':completion:*:*:xdvi:*' file-sort time
174 ---------------------------------------------------------------------------------------------------
176 Completing process IDs with menu selection:
177 ---------------------------------------------------------------------------------------------------
178 zstyle ':completion:*:*:kill:*' menu yes select
179 zstyle ':completion:*:kill:*' force-list always
180 ---------------------------------------------------------------------------------------------------
182 If you end up using a directory as argument, this will remove the
183 trailing slash (usefull in ln)
184 ---------------------------------------------------------------------------------------------------
185 zstyle ':completion:*' squeeze-slashes true
186 ---------------------------------------------------------------------------------------------------
188 cd will never select the parent directory (e.g.: cd ../<TAB>):
189 ---------------------------------------------------------------------------------------------------
190 zstyle ':completion:*:cd:*' ignore-parents parent pwd
191 ---------------------------------------------------------------------------------------------------
193 Another method for 'quick change directories'. Add this to your ~/.zshrc, then just enter
195 ---------------------------------------------------------------------------------------------------
197 if [[ $LBUFFER = *.. ]]; then
203 zle -N rationalise-dot
204 bindkey . rationalise-dot
205 ---------------------------------------------------------------------------------------------------
207 UNSORTED/MISC examples
208 ~~~~~~~~~~~~~~~~~~~~~~
209 Hint: A list of valid glob Qualifiers can be found in zshexpn(1).
210 See ``man 1 zshexpn | less -p'' Qualifiers for details.
212 -------------------------------------------------------------------------------
213 # Get the names of all files that *don't* match a pattern *anywhere* on the
214 # file (and without ``-L'' because its GNUish)
215 $ print -rl -- *(.^e{'grep -q pattern $REPLY'})
217 $ : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'})
220 $ echo $[${RANDOM}%1000] # random between 0-999
221 $ echo $[${RANDOM}%11+10] # random between 10-20
222 $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)
225 $ echo "${(j::)${(@Oa)${(s::):-hello}}}"
227 # Show newest directory
230 # random array element
231 $ FILES=( .../files/* )
232 $ feh $FILES[$RANDOM%$#FILES+1]
234 # cat first line in all files in this dir
235 $ for file (*(ND-.)) IFS= read -re < $file
237 # test if a parameter is numeric
238 $ if [[ $1 == <-> ]] ; then
244 # Show me all the .c files for which there doesn't exist a .o file.
245 $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)
247 # All files in /var/ that are not owned by root
248 $ ls -ld /var/*(^u:root)
250 # All files for which the owner hat read and execute permissions
253 # The same, but also others dont have execute permissions
254 $ echo *(f:u+rx,o-x:)
256 # brace expansion - example
259 $ print -r -- $^X.$^Y
260 A.+ A.- B.+ B.- C.+ C.-
262 # Fetch the newest file containing the string 'fgractg*.log' in the
263 # filename and contains the string 'ORA-' in it
264 $ file=(fgractg*.log(Nm0om[1]))
265 $ (($#file)) && grep -l ORA- $file
267 $ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
268 > if [ -n "$files" ]; then
272 > file=$(ls -td $files | head -1)
273 > grep -l ORA- "$file"
276 # keep specified number of child processes running until entire task finished
277 $ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
279 # Remove zero length and .bak files in a directory
280 $ rm -i *(.L0) *.bak(.)
282 # print out files that dont have extensions
283 $ printf '%s\n' ^?*.*
284 $ printf '%s\n' ^?*.[^.]*(D)
287 # Finding files which does not contain a specific string
288 $ print -rl file* | comm -2 -3 - <(grep -l string file*)'
289 $ for f (file*(N)) grep -q string $f || print -r $f'
291 # Show/Check whether a option is set or not. It works both with $options as
293 $ echo $options[correct]
298 # Count the number of directories on the stack
299 $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
300 $ dirs -v | awk '{n=$1}END{print n+1}'
302 # Matching all files which do not have a dot in filename
305 # Show only the ip-address from ``ifconfig device''
306 # ifconfig from net-tools (Linux)
307 $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}
308 # ifconfig from 4.2BSD {Free,Net,Open}BSD
309 $ print ${$(/sbin/ifconfig tun0)[6]}
311 # Ping all the IP addresses in a couple of class C's or all hosts
313 $ for i in {1..254}; do ping -c 1 192.168.13.$i; done
316 $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done
318 $ for i in $(sed 's/#.*//' > /etc/hosts | awk '{print $2}')
320 : echo "Trying $i ... "
322 : echo '============================='
325 # load all available modules at startup
328 $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
331 # Rename all files within a directory such that their names get a numeral
332 # prefix in the default sort order.
333 $ i=1; for j in *; do mv $j $i.$j; ((i++)); done
334 $ i=1; for f in *; do mv $f $(echo $i | \
335 awk '{ printf("%03d", $0)}').$f; ((i++)); done
336 $ integer i=0; for f in *; do mv $f $[i+=1].$f; done
338 # Find (and print) all symbolic links without a target within the current
340 $ $ file **/*(D@) | fgrep broken
341 $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
342 $ echo **/*(@-^./=%p)
345 # List all plain files that do not have extensions listed in `fignore'
346 $ ls **/*~*(${~${(j/|/)fignore}})(.)
347 # see above, but now omit executables
348 $ ls **/*~*(${~${(j/|/)fignore}})(.^*)
350 # Print out files that dont have extensions (require *setopt extendedglob*
351 # and *setopt dotglob*)
352 $ printf '%s\n' ^?*.*
354 # List files in reverse order sorted by name
357 $ print -rl -- *(^on)
359 # Synonymic to ``ps ax | awk '{print $1}'''
360 $ print -l /proc/*/cwd(:h:t:s/self//)
362 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
366 > for i in /proc/<->/stat
368 > [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
372 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...
373 $ for (( i = 36#n; i <= 36#y; i++ )); do
374 > print ${$(([##36]i)):l}
376 # or in combination with ``dc''
377 $ print {$((##n))..$((##y))}P\ 10P | dc
379 $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'
381 # foreach in one line of shell
382 $ for f (*) print -r -- $f
384 # copy a directory recursively without data/files
389 $ find . -type d -exec env d="$dest_root" \
390 sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
392 # If `foo=23'', then print with 10 digit with leading '0'.
394 $ print ${(r:10::0:)foo}
396 # find the name of all the files in their home directory that have
397 # more than 20 characters in their file names
398 print -rl $HOME/${(l:20::?:)~:-}*
401 $ print -r -- ${(qq)m} > $nameoffile # save it
402 $ eval "m=($(cat -- $nameoffile)" # or use
403 $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
405 # get a "ls -l" on all the files in the tree that are younger than a
406 # specified age (e.g "ls -l" all the files in the tree that where
407 # modified in the last 2 days)
409 # This will give you a listing 1 file perl line (not à la ls -R).
410 # Think of an easy way to have a "ls -R" style output with
411 # only files newer than 2 day old.
412 $ for d (. ./**/*(/)) {
413 > print -r -- $'\n'${d}:
416 > (($#l)) && ls -ltd -- $l
420 # If you also want directories to be included even if their mtime
421 # is more than 2 days old:
422 $ for d (. ./**/*(/)) {
423 > print -r -- $'\n'${d}:
426 > (($#l)) && ls -ltd -- $l
430 # And if you want only the directories with mtime < 2 days to be listed:
431 $ for d (. ./**/*(N/m-2)) {
432 > print -r -- $'\n'${d}:
435 > (($#l)) && ls -ltd -- $l
443 $ echo ${(l:$COLUMNS::-:)}
444 # and now with colors (require autoload colors ;colors)
445 $ echo "$bg[red]$fg[black]${(l:42::-:)}"
447 # Redirect STDERR to a command like xless without redirecting STDOUT as well.
449 # but this executes the command asynchronously. To do it synchronously:
450 $ { { foo 1>&3 } 2>&1 | xless } 3>&1
452 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3
454 > mv $i ${${(C)i}:s/Mp3/mp3/}
457 # Match file names containing only digits and ending with .xml (require
462 # Remove all "non txt" files
465 # Move 200 files from a directory into another
466 $ mv -- *([1,200]) /another/Dir
468 # Convert images (foo.gif => foo.png):
469 $ for i in **/*.gif; convert $i $i:r.png
471 # convert a collection of mp3 files to wave or cdr,
472 # e.g. file.wav -> file.mp3)
473 $ for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
475 # Download with LaTeX2HTML created Files (for example the ZSH-Guide):
476 $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
477 > lynx -source $f >${f:t}
480 # Move all files in dir1 and dir2 that have line counts greater than 10 to
481 # another directory say "/more10"
482 $ mv dir[12]/**/*.cr(-.e{'((`wc -l < $REPLY` > 10))'}) /more10
484 # Make with dpkg a master-list of everyfile that it has installed
485 $ diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort)
487 # Replace this fucking Escape-Sequences:
488 $ autoload colors ; colors
489 $ print "$bg[cyan]$fg[blue]You are a idiot" >> /dev/pts/3
491 # Get ASCII value of a character
492 $ char=N ; print $((#char))
494 # Filename "Erweiterung"
495 # Note: The (N) says to use the nullglob option for this particular
497 $ for i in *.o(N); do
501 # Rename files; i. e. FOO to foo and bar to BAR
502 $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'
503 $ for i in *(.); mv $i ${i:u} # `bar to `BAR'
505 # Show all suid-files in $PATH
506 $ ls -latg ${(s.:.)PATH} | grep '^...s'
508 $ print -l ${^path}/*(Ns,S)
509 # or show only executables with a user given pattern
510 $ print -l ${^path}/*vim*(*N)
512 # gzip files when containing a certain string
513 $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}
515 # A small one-liner, that reads from stdin and prints to stdout the first
516 # unique line i. e. does not print lines that have been printed before
517 # (this is similar to the unique command, but unique can only handle
519 $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}
521 # Lists every executable in PATH
522 $ print -l ${^path}/*(-*N)
524 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?
525 $ ls **/*.c~(*/)#SCCS/*
527 # List all `README' - files case-insensitive with max. one typo
528 $ ls **/*(#ia2)readme
530 # case insensitive checking for variables
531 $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then
532 > echo "Penguin on board."
534 > echo "Not a Linux."
536 -------------------------------------------------------------------------------
538 (Recursive) Globbing - Examples
539 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
540 A list of valid glob Qualifiers can be found in zshexpn(1). *Note:*
541 \*\*/ is equivalent to (*/)#! For example:
542 -------------------------------------------------------------------------------
543 $ print (*/)#zsh_us.ps
544 zsh-4.2.3/Doc/zsh_us.ps
546 zsh-4.2.3/Doc/zsh_us.ps
547 -------------------------------------------------------------------------------
549 -------------------------------------------------------------------------------
550 # Search for `README' in all Subdirectories
553 # find directories that contain both "index.php" and "index.html", or in
554 # general, directories that contain more than one file matching "index.*"
555 $ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
557 $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l >= 2 ))':)
559 # Find command to search for directory name instead of basename
560 $ print -rl /**/*~^*/path(|/*)
562 $ find / | grep -e /path/ -e '/path$'
564 # Print he path of the directories holding the ten biggest C regular files
565 # in the current directory and subdirectories.
566 $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
568 # Find files with size == 0 and send a mail
569 $ files=(**/*(ND.L0m+0m-2))
570 > (( $#files > 0 )) && print -rl -- $files | \
571 mailx -s "empty files" foo@bar.tdl
574 $ chmod 700 **/(.) # Only files
575 $ chmod 700 **/(/) # Only directories
577 # print out all of the files in that directory in 2 columns
578 $ print -rC2 -- ${1:[...]}/*(D:t)
579 # ^- number ob columns
580 # or - if you feel concerned about special characters - use
581 $ list=(${1:[...]}/*(ND:t))
582 $ (($#list)) && print -rC2 -- ${(V)list}
584 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
585 # (recursive, include dotfiles) remove the setgid/setuid flag and print
587 $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))
588 # or with a small script
589 $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {
591 > chmod -s $file && print -r fixed $file
593 # or use ``zargs'' (require autoload zargs) prevent the arg list too
595 $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
597 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
600 # get all files that begin with the date strings from June 4 through
602 $ ls -l 200406{04..10}*(N)
603 # or if they are of the form 200406XX (require ``setopt extended_glob''
604 $ ls -l 200306<4-10>.*
606 # remove spaces from filenames
607 $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
609 # Show only all *.c and *.h - Files
612 # Show only all *.c - files and ignore `foo.c'
615 # show data to *really* binary format
616 $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \
617 > {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' < binary
619 # Show only world-readable files
622 # List files in the current directory are not writable by the owner
623 $ print -l ~/*(ND.^w)
625 # find and delete the files which are older than a given parameter
626 # (seconds/minutes/hours)
627 # deletes all regular file in /Dir that are older than 3 hours
628 $ rm -f /Dir/**/*(.mh+3)
629 # deletes all symlinks in /Dir that are older than 3 minutes
630 $ rm -f /Dir/**/*(@mm+3)
631 # deletes all non dirs in /Dir that are older than 30 seconds
632 $ rm -f /Dir/**/*(ms+30^/)
633 # deletes all folders, sub-folders and files older than one hour
634 $ rm ./**/*(.Dmh+1,.DL0)
635 # deletes all files more than 6 hours old
637 # removes all files but the ten newer ones (delete all but last 10
638 # files in a directory)
640 Note: If you get a arg list too long, you use the builtin rm. For
642 $ zmodload zsh/files ; rm -f **/*(mh+6)
643 or use the zargs function:
644 $ autoload zargs ; zargs **/*(mh+6) -- rm -f
646 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
647 # Matching find all files in all subdirectories, searching recursively,
648 # which have a given name, case insensitive, are at least 50 KB large,
649 # no more than a week old and owned by the root user, and allowing up
650 # to a single error in the spelling of the name. In fact, the required
651 # expression looks like this:
652 $ ls **/(#ia1)name(LK+50mw-1u0)
654 # Change the UID from 102 to 666
655 $ chown 666 **/*(u102)
657 # List all files which have not been updated since last 10 hours
658 $ print -rl -- *(Dmh+10^/)
660 # delete only the oldest file in a directory
661 $ rm ./*filename*(Om[1])
663 # Sort the output from `ls -l' by file size
666 # find most recent file in a directory
667 $ setopt dotglob ; print directory/**/*(om[1])
669 # Show only empty files which nor `group' or `world writable'
672 # find - and list - the ten newest files in directories and subdirs
674 $ print -rl -- **/*(Dom[1,10])
676 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'')
679 # display the 5-10 last modified files
680 $ print -rl -- /path/to/dir/**/*(D.om[5,10])
682 # find all files without a valid owner
683 $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
685 # find all the empty directories in a tree
686 $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
687 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
688 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all
689 # subdirectories with no entries.
692 # remove empty directories afterwards
693 $ rmdir ./**/*(/od) 2> /dev/null
695 # Show only files are owned from group `users'
698 -------------------------------------------------------------------------------
702 Modifiers are a powerful mechanism that let you modify the results
703 returned by parameter, filename and history expansion. See zshexpn(1)
705 -------------------------------------------------------------------------------
706 <<<<<<< /home/dope/download/Source/HG-Repos/zsh-lovers/zsh-lovers.1.txt.orig.432616858
707 # NOTE: Zsh 4.3.4 needed!
709 # files modified today
710 $ print *(e:age today now:)
711 # files modified since 5 pm
712 $ print *(e-age 17:00 now-)
713 # ... since 5 o'clock yesterda
714 $ print *(e-age yesterday,17:00 now-)
715 # ... from last Christmas before today
716 $ print *(e-age 2006/12/25 today-)
717 # ... before yesterday
718 $ print *(e-age 1970/01/01 yesterday-)
719 # all files modified between the start of those dates
720 $ print *(e:age 2006/10/04 2006/10/09:)
721 # all files modified on that date
722 $ print *(e:age 2006/10/04:)
724 $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
726 # Remove a trailing pathname component, leaving the head. This works like
727 ||||||| /tmp/zsh-lovers.1.txt~base.AvW_ZW
728 # Remove a trailing pathname component, leaving the head. This works like
730 # Remove a trailing pathname component, leaving the head. This works like
731 >>>>>>> /tmp/zsh-lovers.1.txt~other.vDaddL
736 # Remove all leading pathname components, leaving the tail. This works
741 # Remove the suffix from each file (*.sh in this example)
742 $f:e is $f file extension
743 :h --> head (dirname)
744 :t --> tail (basename)
745 :r --> rest (extension removed)
746 $ for f (*.sh) mv $f $f:r
748 # Remove a filename extension of the form `.xxx', leaving the root name.
754 # Remove all but the extension.
761 # Print the new command but do not execute it. Only works with history
768 # Quote the substituted words, escaping further substitutions.
775 # Convert the words to all lowercase.
782 # Convert the words to all uppercase.
789 # convert 1st char of a word to uppercase
790 $ foo="one two three four"
791 $ print -r -- "${(C)foo}"
793 -------------------------------------------------------------------------------
797 See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))
799 -------------------------------------------------------------------------------
800 # Append `exit 1' at the end of all *.sh - files
801 $ echo "exit 1" >> *.sh
803 # adding files to foobar.tar.gz
804 $ eval set =(gunzip < foobar.tar.gz) '
805 tar rf $1 additional.txt &&gzip < $1 > foobar.tar.gz'
807 # Redirect output to a file AND display on screen
808 $ foobar >&1 > file1 > file2 > ..
810 # pipe single output to multiple inputs
811 $ zcat foobar.Z >> (gzip -9 > file1.gz) \
812 >> (bzip2 -9 > file1.bz2) \
813 >> (acb --best > file1.acb)
815 # Append /etc/services at the end of file `foo' and `bar'
816 $ cat /etc/services >> foo >> bar
819 $ echo An error >&2 2>&1 | sed -e 's/A/I/'
821 # send standard output of one process to standard input of several processes
824 $ process1 > >(process1) > >(process2)
826 # initializing a variable and simultaneously keeping terminal output
828 $ { a=$(command >&1 >& 3 3 > &- 2>&1);} 3>&1
830 # redirect stderr two times
831 $ setopt multios ; program 2> file2 > file1 2>&1
833 # Duplicating stdout and stderr to a logfile
834 $ exec 3>&1 > logfile 2>&2 2>&1 >&3 3>&-
836 # redirect stderr (only) to a file and to orig. stderr:
837 $ command 2>&2 2>stderr
838 # redirect stderr and stdout to separate files and both to orig. stdout:
839 $ command 2>&1 1>&1 2>stderr 1>stdout
840 # redirect stderr and stdout to separate files and stdout to orig. stdout
841 # AND stderr to orig. stderr:
842 $ command 2>&2 1>&1 2>stderr 1>stdout
844 # More fun with STDERR ;)
845 $ ./my-script.sh 2> >(grep -v moron >error.log)|process-output >output.log
846 $ echo "Thats STDOUT" >>(sed 's/stdout/another example/' > foobar)
847 -------------------------------------------------------------------------------
849 ZMV-Examples (require autoload zmv)
850 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
851 *Note:* '-n' means no execution (just print what would happen). At
852 -------------------------------------------------------------------------------
853 # Remove illegal characters in a fat32 file system. Illegal characters are
855 # NOTE: ``-Q'' and (D) is to include hidden files.
856 $ unwanted='[:;*?\"<>|]'
857 $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
859 # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
860 $ zmv '(*)hell(*)' '${1}heaven${2}'
862 $ zmv '*' '$f:s/hell/heaven/'
864 # remove round bracket within filenames
865 # i. e. foo-(bar).avi -> foo-bar.avi
866 $ zmv '*' '${f//[()]/}'
868 # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
871 1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
872 $ c=1 zmv '*.foo' '$((c++)).foo'
874 1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
876 # Rename "file.with.many.dots.txt" by substituting dots (exept for the last
878 $ touch {1..20}-file.with.many.dots.txt
879 $ zmv '(*.*)(.*)' '${1//./ }$2'
881 # Remove the first 4 chars from a filename
882 $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
884 # Rename names of all files under the current Dir to lower case, but keep
886 $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
888 # replace all 4th character, which is "1", with "2" and so on
890 $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
892 # Remove the first 15 characters from a string
893 $ touch 111111111111111{a-z}
895 $ zmv '*' '$f[16,-1]'
897 # Replace spaces (any number of them) with a single dash in file names
899 $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
901 $ find . -depth -name '* *' -exec bash -c '
906 > newname=${name//*([ -]) *([ -])/-}
907 > mv -i -- "$file" "$Dir/$newname"' {} {} \;
909 # Clean up file names and remove special characters
911 $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
913 # Add *.py to a bunch of python scripts in a directory (some of them end
914 # in *.py and give them all a proper extension
916 $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
918 # lowercase all extensions (i. e. *.JPG) incl. subfolders
920 $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
922 $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
926 > *) mv "$f" "${f%.*}.jpg" ;
930 # remove leading zeros from file extension
933 filename.001 filename.003 filename.005 filename.007 filename.009
934 filename.002 filename.004 filename.006 filename.008 filename.010
935 $ zmv '(filename.)0##(?*)' '$1$2'
937 filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
942 foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
943 $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
945 foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
947 # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
949 $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
951 # See above, but now only files with a filename >= 30 chars
953 $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
955 # Replace spaces in filenames with a underline
957 $ zmv '* *' '$f:gs/ /_'
959 # Change the suffix from *.sh to *.pl
961 $ zmv -W '*.sh' '*.pl'
963 # Add a "".txt" extension to all the files within ${HOME}
964 # ``-.'' is to only rename regular files or symlinks to regular files,
965 # ``D'' is to also rename hidden files (dotfiles))
967 $ zmv -Q '/home/**/*(D-.)' '$f.txt'
968 # Or to only rename files that don't have an extension:
969 $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
971 # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
973 $ chars='[][?=+<>;",*-]'
974 $ zmv '(**/)(*)' '$1${2//$~chars/%}'
976 # Removing single quote from filenames (recursively)
978 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
980 # When a new file arrives (named file.txt) rename all files in order to
981 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
982 # file119.txt and so on ending with file.txt becoming file1.txt
984 $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
986 # lowercase/uppercase all files/directories
988 $ zmv '(*)' '${(L)1}' # lowercase
989 $ zmv '(*)' '${(U)1}' # uppercase
991 # Remove the suffix *.c from all C-Files
995 # Uppercase only the first letter of all *.mp3 - files
997 $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
999 # Copy the target `README' in same directory as each `Makefile'
1001 $ zmv -C '(**/)Makefile' '${1}README'
1003 # Removing single quote from filenames (recursively)
1005 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
1007 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
1009 $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
1010 $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively
1011 -------------------------------------------------------------------------------
1015 Please read zshmodules(1) first!
1017 zsh/pcre (require zmodload zsh/pcre)
1018 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1020 -------------------------------------------------------------------------------
1021 # Copy files of a certain period (date indicated in the filenames)
1023 $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)
1025 $ m() { [[ $1 -pcre-match pcre-regexp ]] }
1027 -------------------------------------------------------------------------------
1029 zsh/clone (require zmodload zsh/clone)
1030 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1031 -------------------------------------------------------------------------------
1032 # Creates a forked instance of the current shell ($! is set to zero) and
1033 # execute ``command'' on /dev/tty8 (for this example).
1034 $ zmodload zsh/clone
1035 $ clone /dev/tty8 && (($! == 0)) && exec command
1036 -------------------------------------------------------------------------------
1038 zsh/datetime (require zmodload zsh/datetime)
1039 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1040 -------------------------------------------------------------------------------
1041 $ zmodload zsh/datetime
1042 $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'
1043 $ export DATE=`datereplacement`
1046 # strip date from filename
1047 $ $ zmodload zsh/datetime
1048 $ setopt extendedglob
1049 $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat
1050 $ strftime -s pattern \
1051 '???_???_<0-%Y%m%d>_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))
1052 $ print -rl -- $~pattern
1053 aaa_bbb_20041212_c.dat
1054 $ print -rl -- $pattern
1055 ???_???_<0-20050815>_?.dat
1057 # Search files size == 0, to be based on the file name containing a date
1058 # rather than the "last modified" date of the file
1059 $ zmodload -i zsh/datetime
1060 $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
1061 $ files=(**/$file(N.L0))
1062 $ (( $#files > 0 )) && print -rl -- $files | \
1063 mailx -s "empty files" foo@bar.tdl
1064 -------------------------------------------------------------------------------
1066 zsh/stat (require zmodload zsh/stat)
1067 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1068 -------------------------------------------------------------------------------
1069 # test if a symbolic link links to a certain file
1070 $ zmodload -i zsh/stat
1071 $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln
1073 # comparing file dates
1077 $ touch bar & sleep 5 & touch foo
1078 $ echo $file1 is $(($(stat +mtime $file2) - \
1079 $(stat +mtime $file1))) seconds older than $file2.
1080 bar is 5 seconds older than foo
1082 # list the files of a disk smaller than some other file
1084 $ stat -A max +size some-other-file
1085 $ print -rl ./**/*(D.L-$max)
1087 # List the top 100 biggest files in a disk
1089 $ ls -fld ./**/*(d`stat +device .`OL[1,100])
1091 # Get only the user name and the file names from (like
1092 # ls -l * | awk '{print $3" " $8}')
1095 > stat -sA user +uid -- "$file" &&
1096 > print -r -- "$user" "$file"
1099 # get the difference between actual bytes of file and allocated bytes of file
1101 $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))
1104 # ``D'' : to include dot files (d lowercase is for device)
1105 # ``O'' : reverse Ordered (o lowercase for non-reverse order)
1106 # ``L'' : by file Length (l is for number of links)
1107 # ``[1]'': return only first one
1109 $ stat +size ./*(DOL[1])
1111 # file size in bytes
1113 $ stat -L +size ~/.zshrc
1116 # Delete files in a directory that hasn't been accessed in the last ten days
1117 # and send ONE mail to the owner of the files informing him/her of the files'
1119 $ zmodload zsh/stat zsh/files
1120 $ typeset -A f; f=()
1121 $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
1122 $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
1124 # Get a "ls -l" on all the files in the tree that are younger than a
1127 $ for d (. ./**/*(N/m-2))
1128 > print -r -- $'\n'$d: && cd $d && {
1130 > stat -F '%b %d %H:%M' -LsAs -- $f &&
1131 > print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \
1132 > ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]}
1136 # get file creation date
1138 $ stat -F '%d %m %Y' +mtime ~/.zshrc
1140 $ stat -F '%D' +mtime ~/.zshrc
1142 -------------------------------------------------------------------------------
1144 zsh/files (require zmodload zsh/files)
1145 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1146 -------------------------------------------------------------------------------
1147 # search a directory for files containing a certain string then copy those
1148 # files to another directory.
1149 $ zmodload zsh/files
1151 $ cp $(grep -lZr foobar .) otherdirectory
1152 -------------------------------------------------------------------------------
1154 zsh/mapfile (require zmodload zsh/mapfile)
1155 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1156 -------------------------------------------------------------------------------
1157 # grepping for two patterns
1158 $ zmodload zsh/mapfile
1160 $ pattern2="bar foo"
1161 $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] && [[ $z = *$pattern1* && \
1162 $z = *$pattern2* ]]'})
1163 # or a solution in combination with zsh/pcre
1164 $ zmodload -i zsh/mapfile zsh/pcre
1166 $ pattern2="bar foo"
1167 $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"
1169 $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})
1171 # equivalent for ``less /etc/passwd | grep -v root''
1172 $ zmodload zsh/mapfile
1174 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}
1175 # or - for case insensitive
1176 $ setopt extendedglob
1177 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
1179 # If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
1180 # this empty tags (ones ending in '/>') so if encountered in the same
1181 # order, the preceeding tags would become ``<TAGA/>1</TAGA>'' and
1182 # ``<TAGB/>2</TAGB>''
1183 $ zmodload zsh/mapfile
1185 $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\
1186 > (#im)<TAGA>*<\/TAGA>/<TAGA>$((++cnt))<\/TAGA>}
1188 # removing all files in users Maildir/new that contain ``filename="gone.src''
1189 $ zmodload zsh/{files,mapfile}
1190 $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \
1191 *filename=\"gone.scr\"* ]]'})
1193 # Grep out the Title from a postscript file and append that value to the
1194 # end of the filename
1196 $ zmodload zsh/mapfile
1197 $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'
1198 -------------------------------------------------------------------------------
1200 zsh/mathfunc (require zmodload zsh/mathfunc)
1201 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1202 -------------------------------------------------------------------------------
1203 $ zmodload zsh/mathfunc
1204 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
1205 -1.1102230246251565e-16
1206 $ echo $(( pi = 4.0 * atan(1.0) ))
1208 $ echo $(( f = sin(0.3) ))
1210 $ print $((1e12 * rand48()))
1212 $ print $(( rand48(seed) ))
1214 -------------------------------------------------------------------------------
1216 zsh/termcap (require zmodload zsh/termcap)
1217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1218 -------------------------------------------------------------------------------
1219 $ zmodload -ab zsh/termcap echotc
1220 $ GREEN=`echotc AF 2`
1221 $ YELLOW=`echotc AF 3`
1223 $ BRIGHTRED=`echotc md ; echotc AF 1`
1224 $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred
1225 -------------------------------------------------------------------------------
1227 zsh/zpty (require zmodload zsh/zpty)
1228 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1229 -------------------------------------------------------------------------------
1233 # ``-r'': read the output of the command name.
1235 $ zpty -r PW z '*password:'
1236 # send the to command name the given strings as input
1238 $ zpty -r PW z '*password:'
1240 # The second form, with the -d option, is used to delete commands
1241 # previously started, by supplying a list of their names. If no names
1242 # are given, all commands are deleted. Deleting a command causes the HUP
1243 # signal to be sent to the corresponding process.
1245 -------------------------------------------------------------------------------
1247 zsh/net/socket (require zmodload zsh/net/socket)
1248 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1249 -------------------------------------------------------------------------------
1250 # ``-l'': open a socket listening on filename
1251 # ``-d'': argument will be taken as the target file descriptor for the
1253 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''
1254 # (3.7.2: File descriptors)
1255 $ zmodload zsh/net/socket
1257 # ``-a'': accept an incoming connection to the socket
1259 $ zsocket -a -d 5 3 # accept a connection
1263 -------------------------------------------------------------------------------
1265 zsh/zftp (require zmodload zsh/zftp)
1266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1267 -------------------------------------------------------------------------------
1268 $ autoload -U zfinit
1270 $ zfparams www.example.invalid myuserid mypassword
1273 $ zfls -l zshtips.html
1274 $ zfput zshtips.html
1275 $ zfls -l zshtips.html
1277 # Automatically transfer files using FTP with error checking
1278 $ autoload -U zfinit ; zfinit
1279 $ zftp open host.name.invalid user passwd || exit
1280 $ zftp get /remote/file > /local/file; r=$?
1281 $ zftp close && exit r
1283 # compress and ftp on the fly
1284 $ autoload -U zfinit ; zfinit
1285 $ zftp open host.name.invalid user password
1286 $ zftp get $file | bzip2 > ${file}.bz2
1290 $ autoload -U zfinit ; zfinit
1293 $ for file in `zfls` ; do
1298 # Upload all regular files in $HOME/foobar (recursive) that are newer than
1299 # two hours to ftp.foobar.invalid/path/to/upload
1300 $ autoload -U zfinit ; zfinit
1301 $ zfopen ftp.foobar.invalid/path/to/upload
1303 $ zfput -r **/*(.mh-2)
1306 # long list of files on a ftp
1307 $ autoload -U zfinit ; zfinit
1309 $ zfcd /some/remote/Dir
1310 $ cd /some/local/Dir
1311 # If the list.txt is located on the remote host, change to
1312 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}
1313 $ zfget ${(f)"$(cat list.txt)"}
1315 -------------------------------------------------------------------------------
1317 zsh/zselect (require zmodload zsh/zselect)
1318 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1319 -------------------------------------------------------------------------------
1323 | $ stty -icanon min 0 time 50
1326 | $ case "$yesno" in
1331 $ zmodload zsh/zselect
1332 $ if zselect -t 500 -r 0 && read yesno && [ yes = "$yesno" ]; then
1337 ------------------------------------------------------------------------------
1343 *auto_cd* (allow one to change to a directory by entering it as a
1344 command). *auto_pushd* (automatically append dirs to the push/pop list)
1345 pushd_ignore_dups (and don't duplicate them).
1349 *no_hup* (don't send HUP signal to background jobs when exiting ZSH).
1350 *print_exit_value* (show a message with the exit code when a command
1351 returns with a non-zero exit code)
1355 *hist_verify* (let the user edit the command line after history
1356 expansion (e.g. !ls) instead of immediately running it) +
1357 Use the same history file for all sessions : +
1358 *setopt SHARE_HISTORY*
1362 *no_clobber* (or set -C; prevent '>' redirection from truncating
1363 the given file if it already exists)
1367 *correct* (automatically correct the spelling of commands).
1368 *correct_all* (automatically correct the spelling of each word on the
1369 command line) *dvorak* (dvorak layout)
1373 Mailpath: simple multiple mailpath:
1374 -----------------------------------------------------
1375 mailpath=($HOME/Mail/mbox'?new mail in mbox'
1376 $HOME/Mail/tux.u-strasbg'?new mail in tux'
1377 $HOME/Mail/lilo'?new mail in lilo'
1378 $HOME/Mail/ldap-fr'?new mail in ldap-fr')
1379 -----------------------------------------------------
1381 Mailpath: dynamic mailpath:
1382 -----------------------------------------------------
1384 for i in ~/Mail/Lists/*(.); do
1385 mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."
1387 -----------------------------------------------------
1388 Avoid globbing on special commands:
1389 --------------------------------------------------------
1390 for com in alias expr find mattrib mcopy mdir mdel which;
1391 alias $com="noglob $com"
1392 --------------------------------------------------------
1394 For migrating your bashprompt to zsh use the script bash2zshprompt located in
1395 the zsh source distribution under 'Misc'.
1397 For migration from (t)csh to zsh use the c2z tool that converts csh
1398 aliases and environment and shell variables to zsh. It does this by running
1399 csh, and having csh report on aliases and variables. The script then converts
1400 these to zsh startup files. It has some issues and usage information that are
1401 documented at the top of this script.
1403 Here are functions to set the title and hardstatus of an *XTerm* or of *GNU
1404 Screen* to 'zsh' and the current directory, respectively, when the prompt is
1405 displayed, and to the command name and rest of the command line, respectively,
1406 when a command is executed:
1407 ------------------------------------------------------------------
1409 if [[ $TERM == "screen" ]]; then
1410 # Use these two for GNU Screen:
1411 print -nR $' 33k'$1$' 33'\
1412 print -nR $' 33]0;'$2$''
1413 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
1414 # Use this one instead for XTerms:
1415 print -nR $' 33]0;'$*$''
1418 function precmd { title zsh "$PWD" }
1421 local -a cmd; cmd=(${(z)1})
1422 title $cmd[1]:t "$cmd[2,-1]"
1424 ------------------------------------------------------------------
1426 Put the following line into your ~/.screenrc to see this fancy hardstatus:
1427 -----------------------------------------
1428 caption always "%3n %t%? (%u)%?%?: %h%?"
1429 -----------------------------------------
1432 Special variables which are assigned:
1433 ------------------------------------------------------
1434 $LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID
1435 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath
1436 ------------------------------------------------------
1441 *http://www.zsh.org/[]*
1443 *http://sourceforge.net/projects/zsh/[]*
1444 Z shell page at sunsite.dk::
1445 *http://zsh.sunsite.dk/[]*
1446 From Bash to Z Shell: Conquering the Command Line - the book::
1447 *http://www.bash2zsh.com/[]*
1448 Mailinglistarchive::
1449 *http://www.zsh.org/mla/[]*
1451 *http://www.zsh.org/FAQ/[]*
1453 *http://zsh.sunsite.dk/Guide/[]*
1455 *http://www.zshwiki.org/[]*
1456 Die Zsh als interaktive Shell::
1457 *http://cssun.rrze.uni-erlangen.de/~sipakale/zshreferat.html[]*
1458 A short introduction from BYU::
1459 *http://docs.cs.byu.edu/docs/zsh/index.php[]*
1461 *http://stchaz.free.fr/mouse.zsh[]*
1462 Shell Corner: Zsh Suite of "keeper" Functions::
1463 *http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm[]*
1464 The Z Shell (A Fan Page)::
1465 *http://www.princeton.edu/~kmccarty/zsh.html[]*
1466 Making the Transition to Zsh::
1467 *http://www.linux-mag.com/cgi-bin/printer.pl?issue=2002-05&article=power[]*
1468 Curtains up: introducing the Z shell::
1469 *http://www-128.ibm.com/developerworks/linux/library/l-z.html?dwzone=linux[]*
1470 ZSH-Liebhaberseite::
1471 *http://michael-prokop.at/computer/tools_zsh_liebhaber.html[]*
1472 ZSH-Seite von Michael Prokop::
1473 *http://www.michael-prokop.at/computer/tools_zsh.html[]*
1474 A Case for the Z Shell on *http://www.daemonnews.org/[]*::
1475 *http://ezine.daemonnews.org/199910/zsh.html[]*
1476 ZSH-Section from Dotfiles.com::
1477 *http://www.dotfiles.com/index.php?app_id=4[]*
1478 Writing Zsh Completion Functions::
1479 *http://www.linux-mag.com/2002-07/power_01.html[]*
1480 ZSH Prompt introduction::
1481 *http://aperiodic.net/phil/prompt/[]*
1483 *http://www.adamspiers.org/computing/zsh/[]*
1484 Zzappers Best of ZSH Tips::
1485 *http://www.rayninfo.co.uk/tips/zshtips.html[]*
1486 Zsh Webpage by Christian Schneider::
1487 *http://strcat.de/wiki/zsh/[]*
1488 *http://strcat.de/wiki/zsh-german[]* (German translation. Help needed!)
1489 The zsh-lovers webpage::
1490 *http://grml.org/zsh/[]*
1492 *#zsh at irc.freenode.org*
1493 The Z shell reference-card (included in the zsh-lovers debian-package)::
1494 *http://www.bash2zsh.com/zsh_refcard/refcard.pdf[]*
1498 This manpage was written by Michael Prokop, Christian 'strcat'
1499 Schneider and Matthias Kopfermann. But many ideas have been taken from
1500 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),
1501 google, newsgroups and the zsh-Wiki. +
1502 Thanks for your cool and incredible tips. We learned much from you!
1504 In alphabetic order:
1505 -------------------------------------------------------------------------
1506 Andrew 'zefram' Main - http://www.fysh.org/~zefram/
1507 Barton E. Schaefer - http://www.well.com/user/barts/
1508 Matthias Kopfermann - http://www.infodrom.north.de/~matthi/
1509 Oliver Kiddle - http://people.freenet.de/opk/
1510 Paul Falstad - http://www.falstad.com/
1511 Peter Stephenson - http://homepage.ntlworld.com/p.w.stephenson/
1513 Stephane Chazelas - http://stephane.chazelas.free.fr/
1514 Sven Guckes - http://www.guckes.net/
1515 Sven Wischnowsky - http://w9y.de/zsh/zshrc
1516 -------------------------------------------------------------------------
1521 ------------------------------------------------------------------
1523 zshall Tthe Z shell meta-man page
1524 zshbuiltins Zsh built-in commands
1525 zshcalsys zsh calendar system
1526 zshcompctl zsh programmable completion
1527 zshcompsys Zsh completion system
1528 zshcompwid Zsh completion widgets
1529 zshcontrib User contributions to zsh
1530 zshexpn Zsh expansion and substitution
1531 zshmisc Anything not fitting into the other sections
1532 zshmodules Zsh loadable modules
1533 zshoptions Zsh options
1534 zshparam Zsh parameters
1535 zshroadmap Informal introduction to the zsh manual
1536 zshtcpsys Zsh tcp system
1537 zshzle Zsh command line editing
1538 zshzftpsys Zsh built-in FTP client
1539 zshall Meta-man page containing all of the above
1540 ------------------------------------------------------------------
1542 Note: especially 'man zshcontrib' covers very useful topics! +
1543 Book: *From Bash to Z Shell* by Oliver Kiddle, Jerry Peck and Peter
1544 Stephenson. *ISBN: 1590593766*. - *http://www.bash2zsh.com/[bash2zsh.com]* +
1545 Also take a look at the section *LINKS* in this manpage.
1549 Probably. This manpage might be never complete. So please report bugs,
1550 feedback and suggestions to <zsh-lovers@michael-prokop.at>. Thank
1555 Copyright \(C) Michael Prokop, Christian Schneider and Matthias