1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
\r
6 <meta name="generator" content="AsciiDoc 8.5.2" />
\r
7 <title>ZSH-LOVERS(1)</title>
\r
8 <style type="text/css">
\r
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
\r
12 border: 1px solid red;
\r
17 margin: 1em 5% 1em 5%;
\r
22 text-decoration: underline;
\r
42 h1, h2, h3, h4, h5, h6 {
\r
44 font-family: sans-serif;
\r
46 margin-bottom: 0.5em;
\r
51 border-bottom: 2px solid silver;
\r
69 border: 1px solid silver;
\r
74 margin-bottom: 0.5em;
\r
88 font-family: sans-serif;
\r
94 span#revnumber, span#revdate, span#revremark {
\r
95 font-family: sans-serif;
\r
99 font-family: sans-serif;
\r
101 border-top: 2px solid silver;
\r
102 padding-top: 0.5em;
\r
107 padding-bottom: 0.5em;
\r
109 div#footer-badges {
\r
111 padding-bottom: 0.5em;
\r
116 margin-bottom: 1.5em;
\r
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
\r
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
120 div.admonitionblock {
\r
122 margin-bottom: 1.5em;
\r
124 div.admonitionblock {
\r
126 margin-bottom: 2.0em;
\r
131 div.content { /* Block element content. */
\r
135 /* Block element titles. */
\r
136 div.title, caption.title {
\r
138 font-family: sans-serif;
\r
142 margin-bottom: 0.5em;
\r
148 td div.title:first-child {
\r
151 div.content div.title:first-child {
\r
154 div.content + div.title {
\r
158 div.sidebarblock > div.content {
\r
159 background: #ffffee;
\r
160 border: 1px solid silver;
\r
164 div.listingblock > div.content {
\r
165 border: 1px solid silver;
\r
166 background: #f4f4f4;
\r
170 div.quoteblock, div.verseblock {
\r
171 padding-left: 1.0em;
\r
172 margin-left: 1.0em;
\r
174 border-left: 5px solid #dddddd;
\r
178 div.quoteblock > div.attribution {
\r
179 padding-top: 0.5em;
\r
183 div.verseblock > div.content {
\r
186 div.verseblock > div.attribution {
\r
187 padding-top: 0.75em;
\r
190 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
\r
191 div.verseblock + div.attribution {
\r
195 div.admonitionblock .icon {
\r
196 vertical-align: top;
\r
199 text-decoration: underline;
\r
201 padding-right: 0.5em;
\r
203 div.admonitionblock td.content {
\r
204 padding-left: 0.5em;
\r
205 border-left: 3px solid #dddddd;
\r
208 div.exampleblock > div.content {
\r
209 border-left: 3px solid #dddddd;
\r
210 padding-left: 0.5em;
\r
213 div.imageblock div.content { padding-left: 0; }
\r
214 span.image img { border-style: none; }
\r
215 a.image:visited { color: white; }
\r
219 margin-bottom: 0.8em;
\r
224 font-style: normal;
\r
227 dd > *:first-child {
\r
232 list-style-position: outside;
\r
235 list-style-type: decimal;
\r
238 list-style-type: lower-alpha;
\r
241 list-style-type: upper-alpha;
\r
244 list-style-type: lower-roman;
\r
247 list-style-type: upper-roman;
\r
250 div.compact ul, div.compact ol,
\r
251 div.compact p, div.compact p,
\r
252 div.compact div, div.compact div {
\r
254 margin-bottom: 0.1em;
\r
257 div.tableblock > table {
\r
258 border: 3px solid #527bbd;
\r
260 thead, p.table.header {
\r
261 font-family: sans-serif;
\r
273 /* Because the table frame attribute is overriden by CSS in most browsers. */
\r
274 div.tableblock > table[frame="void"] {
\r
275 border-style: none;
\r
277 div.tableblock > table[frame="hsides"] {
\r
278 border-left-style: none;
\r
279 border-right-style: none;
\r
281 div.tableblock > table[frame="vsides"] {
\r
282 border-top-style: none;
\r
283 border-bottom-style: none;
\r
289 margin-bottom: 0.8em;
\r
292 padding-bottom: 15px;
\r
294 dt.hdlist1.strong, td.hdlist1.strong {
\r
298 vertical-align: top;
\r
299 font-style: normal;
\r
300 padding-right: 0.8em;
\r
304 vertical-align: top;
\r
306 div.hdlist.compact tr {
\r
312 background: yellow;
\r
315 .footnote, .footnoteref {
\r
319 span.footnote, span.footnoteref {
\r
320 vertical-align: super;
\r
324 margin: 20px 0 20px 0;
\r
325 padding: 7px 0 0 0;
\r
328 #footnotes div.footnote {
\r
334 border-top: 1px solid silver;
\r
344 div#footer-badges { display: none; }
\r
348 margin-bottom: 2.5em;
\r
353 font-family: sans-serif;
\r
357 margin-bottom: 0.1em;
\r
360 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
\r
376 /* Workarounds for IE6's broken and incomplete CSS2. */
\r
378 div.sidebar-content {
\r
379 background: #ffffee;
\r
380 border: 1px solid silver;
\r
383 div.sidebar-title, div.image-title {
\r
385 font-family: sans-serif;
\r
388 margin-bottom: 0.5em;
\r
391 div.listingblock div.content {
\r
392 border: 1px solid silver;
\r
393 background: #f4f4f4;
\r
397 div.quoteblock-attribution {
\r
398 padding-top: 0.5em;
\r
402 div.verseblock-content {
\r
405 div.verseblock-attribution {
\r
406 padding-top: 0.75em;
\r
410 div.exampleblock-content {
\r
411 border-left: 3px solid #dddddd;
\r
412 padding-left: 0.5em;
\r
415 /* IE6 sets dynamically generated links as visited. */
\r
416 div#toc a:visited { color: blue; }
\r
418 <script type="text/javascript">
\r
420 window.onload = function(){asciidoc.footnotes();}
\r
421 var asciidoc = { // Namespace.
\r
423 /////////////////////////////////////////////////////////////////////
\r
424 // Table Of Contents generator
\r
425 /////////////////////////////////////////////////////////////////////
\r
427 /* Author: Mihai Bazon, September 2002
\r
428 * http://students.infoiasi.ro/~mishoo
\r
430 * Table Of Content generator
\r
433 * Feel free to use this script under the terms of the GNU General Public
\r
434 * License, as long as you do not remove or alter this notice.
\r
437 /* modified by Troy D. Hanson, September 2006. License: GPL */
\r
438 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
\r
440 // toclevels = 1..4.
\r
441 toc: function (toclevels) {
\r
443 function getText(el) {
\r
445 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
446 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
\r
448 else if (i.firstChild != null)
\r
449 text += getText(i);
\r
454 function TocEntry(el, text, toclevel) {
\r
457 this.toclevel = toclevel;
\r
460 function tocEntries(el, toclevels) {
\r
461 var result = new Array;
\r
462 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
\r
463 // Function that scans the DOM tree for header elements (the DOM2
\r
464 // nodeIterator API would be a better technique but not supported by all
\r
466 var iterate = function (el) {
\r
467 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
468 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
\r
469 var mo = re.exec(i.tagName);
\r
470 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
\r
471 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
\r
481 var toc = document.getElementById("toc");
\r
482 var entries = tocEntries(document.getElementById("content"), toclevels);
\r
483 for (var i = 0; i < entries.length; ++i) {
\r
484 var entry = entries[i];
\r
485 if (entry.element.id == "")
\r
486 entry.element.id = "_toc_" + i;
\r
487 var a = document.createElement("a");
\r
488 a.href = "#" + entry.element.id;
\r
489 a.appendChild(document.createTextNode(entry.text));
\r
490 var div = document.createElement("div");
\r
491 div.appendChild(a);
\r
492 div.className = "toclevel" + entry.toclevel;
\r
493 toc.appendChild(div);
\r
495 if (entries.length == 0)
\r
496 toc.parentNode.removeChild(toc);
\r
500 /////////////////////////////////////////////////////////////////////
\r
501 // Footnotes generator
\r
502 /////////////////////////////////////////////////////////////////////
\r
504 /* Based on footnote generation code from:
\r
505 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
\r
508 footnotes: function () {
\r
509 var cont = document.getElementById("content");
\r
510 var noteholder = document.getElementById("footnotes");
\r
511 var spans = cont.getElementsByTagName("span");
\r
514 for (i=0; i<spans.length; i++) {
\r
515 if (spans[i].className == "footnote") {
\r
517 // Use [\s\S] in place of . so multi-line matches work.
\r
518 // Because JavaScript has no s (dotall) regex flag.
\r
519 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
\r
520 noteholder.innerHTML +=
\r
521 "<div class='footnote' id='_footnote_" + n + "'>" +
\r
522 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
\r
523 n + "</a>. " + note + "</div>";
\r
524 spans[i].innerHTML =
\r
525 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
\r
526 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
527 var id =spans[i].getAttribute("id");
\r
528 if (id != null) refs["#"+id] = n;
\r
532 noteholder.parentNode.removeChild(noteholder);
\r
534 // Process footnoterefs.
\r
535 for (i=0; i<spans.length; i++) {
\r
536 if (spans[i].className == "footnoteref") {
\r
537 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
\r
538 href = href.match(/#.*/)[0]; // Because IE return full URL.
\r
540 spans[i].innerHTML =
\r
541 "[<a href='#_footnote_" + n +
\r
542 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
554 <h1>ZSH-LOVERS(1)</h1>
\r
557 <h2 id="_name">NAME</h2>
\r
558 <div class="sectionbody">
\r
559 <div class="paragraph"><p>zsh-lovers - tips, tricks and examples for the Z shell</p></div>
\r
561 <h2 id="_synopsis">SYNOPSIS</h2>
\r
562 <div class="sectionbody">
\r
563 <div class="paragraph"><p>Just read it. ;-)</p></div>
\r
565 <h2 id="_overview">OVERVIEW</h2>
\r
566 <div class="sectionbody">
\r
567 <div class="paragraph"><p>Whenever we look at the zsh manual we wonder why there are no examples or those
\r
568 simply things in (shell) life. The zsh contains many features, but there was no
\r
569 manpage with some examples (like procmailex(5)). That’s why we wrote this
\r
571 <div class="paragraph"><p>Most of the tricks and oneliner come from the mailinglists zsh-users,
\r
572 zsh-workers, google, newsgroups and from ourself. See section <strong>LINKS</strong> for
\r
574 <div class="paragraph"><p>Note: This manpage (zsh-lovers(1)) is <strong>not</strong> an offical part of the Z shell! It’s
\r
575 just a just for fun - manpage ;)<br />
\r
576 For comments, bugreports and feedback take a quick look at the section <strong>BUGS</strong>.</p></div>
\r
578 <h2 id="_shell_scripting">SHELL-SCRIPTING</h2>
\r
579 <div class="sectionbody">
\r
580 <div class="paragraph"><p>This section provides some examples for often needed shellscript-stuff. Notice
\r
581 that you should not use otherwise most examples won’t work.<br />
\r
582 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski
\r
583 (<a href="http://www.chodorowski.com/projects/zws/">http://www.chodorowski.com/projects/zws/</a>):</p></div>
\r
584 <div class="listingblock">
\r
585 <div class="content">
\r
586 <pre><tt>parse_options()
\r
592 zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help
\r
593 if [[ $? != 0 || "$o_help" != "" ]]; then
\r
594 echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"
\r
602 if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi
\r
604 # now use the function:
\r
605 parse_options $*</tt></pre>
\r
608 <h2 id="_examples">EXAMPLES</h2>
\r
609 <div class="sectionbody">
\r
610 <div class="paragraph"><p>Available subsections are <strong>Aliases</strong>, <strong>Completion</strong>, <strong>Unsorted/Misc examples</strong>,
\r
611 <strong>(Recursive) Globbing - Examples</strong>, <strong>Modifiers usage</strong>, <strong>Redirection-Examples</strong>,
\r
612 <strong>ZMV-Examples</strong> and <strong>Module-Examples</strong>.</p></div>
\r
613 <h3 id="_aliases">ALIASES</h3><div style="clear:left"></div>
\r
614 <div class="paragraph"><p>Suffix aliases are supported in zsh since version 4.2.0. Some examples:</p></div>
\r
615 <div class="listingblock">
\r
616 <div class="content">
\r
617 <pre><tt>alias -s tex=vim
\r
619 alias -s org=w3m</tt></pre>
\r
621 <div class="paragraph"><p>Now pressing return-key after entering <em>foobar.tex</em> starts vim with
\r
622 foobar.tex. Calling a html-file runs browser w3m. <em>www.zsh.org</em> and pressing
\r
623 enter starts w3m with argument www.zsh.org.<br />
\r
624 Global aliases can be used anywhere in the command line. Example:</p></div>
\r
625 <div class="listingblock">
\r
626 <div class="content">
\r
627 <pre><tt>$ alias -g C='| wc -l'
\r
628 $ grep alias ~/.zsh/* C
\r
631 <div class="paragraph"><p>Some more or less useful global aliases (choose whether they are useful or not
\r
632 for you on your own):</p></div>
\r
633 <div class="listingblock">
\r
634 <div class="content">
\r
635 <pre><tt>alias -g ...='../..'
\r
636 alias -g ....='../../..'
\r
637 alias -g .....='../../../..'
\r
638 alias -g CA="2>&1 | cat -A"
\r
639 alias -g C='| wc -l'
\r
640 alias -g D="DISPLAY=:0.0"
\r
641 alias -g DN=/dev/null
\r
642 alias -g ED="export DISPLAY=:0.0"
\r
643 alias -g EG='|& egrep'
\r
644 alias -g EH='|& head'
\r
645 alias -g EL='|& less'
\r
646 alias -g ELS='|& less -S'
\r
647 alias -g ETL='|& tail -20'
\r
648 alias -g ET='|& tail'
\r
649 alias -g F=' | fmt -'
\r
650 alias -g G='| egrep'
\r
651 alias -g H='| head'
\r
652 alias -g HL='|& head -20'
\r
653 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"
\r
654 alias -g LL="2>&1 | less"
\r
655 alias -g L="| less"
\r
656 alias -g LS='| less -S'
\r
657 alias -g MM='| most'
\r
658 alias -g M='| more'
\r
659 alias -g NE="2> /dev/null"
\r
660 alias -g NS='| sort -n'
\r
661 alias -g NUL="> /dev/null 2>&1"
\r
663 alias -g R=' > /c/aaa/tee.txt '
\r
664 alias -g RNS='| sort -nr'
\r
665 alias -g S='| sort'
\r
666 alias -g TL='| tail -20'
\r
667 alias -g T='| tail'
\r
668 alias -g US='| sort -u'
\r
669 alias -g VM=/var/log/messages
\r
670 alias -g X0G='| xargs -0 egrep'
\r
671 alias -g X0='| xargs -0'
\r
672 alias -g XG='| xargs egrep'
\r
673 alias -g X='| xargs'</tt></pre>
\r
675 <h3 id="_completion">COMPLETION</h3><div style="clear:left"></div>
\r
676 <div class="paragraph"><p>See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old
\r
677 style of zsh programmable completion, zshcompsys is the new completion
\r
678 system, zshcompwid are the zsh completion widgets.</p></div>
\r
679 <div class="paragraph"><p>Some functions, like _apt and _dpkg, are very slow. You can use a cache
\r
680 in order to proxy the list of results (like the list of available
\r
681 debian packages) Use a cache:</p></div>
\r
682 <div class="listingblock">
\r
683 <div class="content">
\r
684 <pre><tt>zstyle ':completion:*' use-cache on
\r
685 zstyle ':completion:*' cache-path ~/.zsh/cache</tt></pre>
\r
687 <div class="paragraph"><p>Prevent CVS files/directories from being completed:</p></div>
\r
688 <div class="listingblock">
\r
689 <div class="content">
\r
690 <pre><tt>zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
\r
691 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'</tt></pre>
\r
693 <div class="paragraph"><p>Fuzzy matching of completions for when you mistype them:</p></div>
\r
694 <div class="listingblock">
\r
695 <div class="content">
\r
696 <pre><tt>zstyle ':completion:*' completer _complete _match _approximate
\r
697 zstyle ':completion:*:match:*' original only
\r
698 zstyle ':completion:*:approximate:*' max-errors 1 numeric</tt></pre>
\r
700 <div class="paragraph"><p>And if you want the number of errors allowed by _approximate to
\r
701 increase with the length of what you have typed so far:</p></div>
\r
702 <div class="listingblock">
\r
703 <div class="content">
\r
704 <pre><tt>zstyle -e ':completion:*:approximate:*' \
\r
705 max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'</tt></pre>
\r
707 <div class="paragraph"><p>Ignore completion functions for commands you don’t have:</p></div>
\r
708 <div class="listingblock">
\r
709 <div class="content">
\r
710 <pre><tt>zstyle ':completion:*:functions' ignored-patterns '_*'</tt></pre>
\r
712 <div class="paragraph"><p>With helper functions like:</p></div>
\r
713 <div class="listingblock">
\r
714 <div class="content">
\r
715 <pre><tt>xdvi() { command xdvi ${*:-*.dvi(om[1])} }</tt></pre>
\r
717 <div class="paragraph"><p>you can avoid having to complete at all in many cases, but if you do,
\r
718 you might want to fall into menu selection immediately and to have the
\r
719 words sorted by time:</p></div>
\r
720 <div class="listingblock">
\r
721 <div class="content">
\r
722 <pre><tt>zstyle ':completion:*:*:xdvi:*' menu yes select
\r
723 zstyle ':completion:*:*:xdvi:*' file-sort time</tt></pre>
\r
725 <div class="paragraph"><p>Completing process IDs with menu selection:</p></div>
\r
726 <div class="listingblock">
\r
727 <div class="content">
\r
728 <pre><tt>zstyle ':completion:*:*:kill:*' menu yes select
\r
729 zstyle ':completion:*:kill:*' force-list always</tt></pre>
\r
731 <div class="paragraph"><p>If you end up using a directory as argument, this will remove the
\r
732 trailing slash (usefull in ln)</p></div>
\r
733 <div class="listingblock">
\r
734 <div class="content">
\r
735 <pre><tt>zstyle ':completion:*' squeeze-slashes true</tt></pre>
\r
737 <div class="paragraph"><p>cd will never select the parent directory (e.g.: cd ../<TAB>):</p></div>
\r
738 <div class="listingblock">
\r
739 <div class="content">
\r
740 <pre><tt>zstyle ':completion:*:cd:*' ignore-parents parent pwd</tt></pre>
\r
742 <div class="paragraph"><p>Another method for <em>quick change directories</em>. Add this to your ~/.zshrc, then just enter
\r
743 “cd …./dir”</p></div>
\r
744 <div class="listingblock">
\r
745 <div class="content">
\r
746 <pre><tt>rationalise-dot() {
\r
747 if [[ $LBUFFER = *.. ]]; then
\r
753 zle -N rationalise-dot
\r
754 bindkey . rationalise-dot</tt></pre>
\r
756 <h3 id="_unsorted_misc_examples">UNSORTED/MISC examples</h3><div style="clear:left"></div>
\r
757 <div class="paragraph"><p>Hint: A list of valid glob Qualifiers can be found in zshexpn(1).
\r
758 See “man 1 zshexpn | less -p” Qualifiers for details.</p></div>
\r
759 <div class="listingblock">
\r
760 <div class="content">
\r
761 <pre><tt># Get the names of all files that *don't* match a pattern *anywhere* on the
\r
762 # file (and without ``-L'' because its GNUish)
\r
763 $ print -rl -- *(.^e{'grep -q pattern $REPLY'})
\r
765 $ : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'})
\r
768 $ echo $[${RANDOM}%1000] # random between 0-999
\r
769 $ echo $[${RANDOM}%11+10] # random between 10-20
\r
770 $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)
\r
773 $ echo "${(j::)${(@Oa)${(s::):-hello}}}"
\r
775 # Show newest directory
\r
778 # random array element
\r
779 $ FILES=( .../files/* )
\r
780 $ feh $FILES[$RANDOM%$#FILES+1]
\r
782 # cat first line in all files in this dir
\r
783 $ for file (*(ND-.)) IFS= read -re < $file
\r
785 # test if a parameter is numeric
\r
786 $ if [[ $1 == <-> ]] ; then
\r
792 # Show me all the .c files for which there doesn't exist a .o file.
\r
793 $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)
\r
795 # All files in /var/ that are not owned by root
\r
796 $ ls -ld /var/*(^u:root)
\r
798 # All files for which the owner hat read and execute permissions
\r
801 # The same, but also others dont have execute permissions
\r
802 $ echo *(f:u+rx,o-x:)
\r
804 # brace expansion - example
\r
807 $ print -r -- $^X.$^Y
\r
808 A.+ A.- B.+ B.- C.+ C.-
\r
810 # Fetch the newest file containing the string 'fgractg*.log' in the
\r
811 # filename and contains the string 'ORA-' in it
\r
812 $ file=(fgractg*.log(Nm0om[1]))
\r
813 $ (($#file)) && grep -l ORA- $file
\r
815 $ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
\r
816 > if [ -n "$files" ]; then
\r
820 > file=$(ls -td $files | head -1)
\r
821 > grep -l ORA- "$file"
\r
824 # keep specified number of child processes running until entire task finished
\r
825 $ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
\r
827 # Remove zero length and .bak files in a directory
\r
828 $ rm -i *(.L0) *.bak(.)
\r
830 # print out files that dont have extensions
\r
831 $ printf '%s\n' ^?*.*
\r
832 $ printf '%s\n' ^?*.[^.]*(D)
\r
833 $ ls -d -- ^?*.*(D)
\r
835 # Finding files which does not contain a specific string
\r
836 $ print -rl file* | comm -2 -3 - <(grep -l string file*)'
\r
837 $ for f (file*(N)) grep -q string $f || print -r $f'
\r
839 # Show/Check whether a option is set or not. It works both with $options as
\r
841 $ echo $options[correct]
\r
846 # Count the number of directories on the stack
\r
847 $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
\r
848 $ dirs -v | awk '{n=$1}END{print n+1}'
\r
850 # Matching all files which do not have a dot in filename
\r
853 # Show only the ip-address from ``ifconfig device''
\r
854 # ifconfig from net-tools (Linux)
\r
855 $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}
\r
856 # ifconfig from 4.2BSD {Free,Net,Open}BSD
\r
857 $ print ${$(/sbin/ifconfig tun0)[6]}
\r
859 # Ping all the IP addresses in a couple of class C's or all hosts
\r
861 $ for i in {1..254}; do ping -c 1 192.168.13.$i; done
\r
864 $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done
\r
866 $ for i in $(sed 's/#.*//' > /etc/hosts | awk '{print $2}')
\r
868 : echo "Trying $i ... "
\r
870 : echo '============================='
\r
873 # load all available modules at startup
\r
876 $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
\r
879 # Rename all files within a directory such that their names get a numeral
\r
880 # prefix in the default sort order.
\r
881 $ i=1; for j in *; do mv $j $i.$j; ((i++)); done
\r
882 $ i=1; for f in *; do mv $f $(echo $i | \
\r
883 awk '{ printf("%03d", $0)}').$f; ((i++)); done
\r
884 $ integer i=0; for f in *; do mv $f $[i+=1].$f; done
\r
886 # Find (and print) all symbolic links without a target within the current
\r
888 $ $ file **/*(D@) | fgrep broken
\r
889 $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
\r
890 $ echo **/*(@-^./=%p)
\r
891 $ print -l **/*(-@)
\r
893 # List all plain files that do not have extensions listed in `fignore'
\r
894 $ ls **/*~*(${~${(j/|/)fignore}})(.)
\r
895 # see above, but now omit executables
\r
896 $ ls **/*~*(${~${(j/|/)fignore}})(.^*)
\r
898 # Print out files that dont have extensions (require *setopt extendedglob*
\r
899 # and *setopt dotglob*)
\r
900 $ printf '%s\n' ^?*.*
\r
902 # List files in reverse order sorted by name
\r
903 $ print -rl -- *(On)
\r
905 $ print -rl -- *(^on)
\r
907 # Synonymic to ``ps ax | awk '{print $1}'''
\r
908 $ print -l /proc/*/cwd(:h:t:s/self//)
\r
910 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
\r
914 > for i in /proc/<->/stat
\r
916 > [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
\r
920 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...
\r
921 $ for (( i = 36#n; i <= 36#y; i++ )); do
\r
922 > print ${$(([##36]i)):l}
\r
924 # or in combination with ``dc''
\r
925 $ print {$((##n))..$((##y))}P\ 10P | dc
\r
927 $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'
\r
929 # foreach in one line of shell
\r
930 $ for f (*) print -r -- $f
\r
932 # copy a directory recursively without data/files
\r
935 $ mkdir -p -- $dirs
\r
937 $ find . -type d -exec env d="$dest_root" \
\r
938 sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
\r
940 # If `foo=23'', then print with 10 digit with leading '0'.
\r
942 $ print ${(r:10::0:)foo}
\r
944 # find the name of all the files in their home directory that have
\r
945 # more than 20 characters in their file names
\r
946 print -rl $HOME/${(l:20::?:)~:-}*
\r
949 $ print -r -- ${(qq)m} > $nameoffile # save it
\r
950 $ eval "m=($(cat -- $nameoffile)" # or use
\r
951 $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
\r
953 # get a "ls -l" on all the files in the tree that are younger than a
\r
954 # specified age (e.g "ls -l" all the files in the tree that where
\r
955 # modified in the last 2 days)
\r
956 $ ls -tld **/*(m-2)
\r
957 # This will give you a listing 1 file perl line (not à la ls -R).
\r
958 # Think of an easy way to have a "ls -R" style output with
\r
959 # only files newer than 2 day old.
\r
960 $ for d (. ./**/*(/)) {
\r
961 > print -r -- $'\n'${d}:
\r
962 > cd $d && {
\r
964 > (($#l)) && ls -ltd -- $l
\r
968 # If you also want directories to be included even if their mtime
\r
969 # is more than 2 days old:
\r
970 $ for d (. ./**/*(/)) {
\r
971 > print -r -- $'\n'${d}:
\r
972 > cd $d && {
\r
974 > (($#l)) && ls -ltd -- $l
\r
978 # And if you want only the directories with mtime < 2 days to be listed:
\r
979 $ for d (. ./**/*(N/m-2)) {
\r
980 > print -r -- $'\n'${d}:
\r
981 > cd $d && {
\r
983 > (($#l)) && ls -ltd -- $l
\r
989 $ echo ${(l:42::-:)}
\r
990 # or use ``$COLUMS''
\r
991 $ echo ${(l:$COLUMNS::-:)}
\r
992 # and now with colors (require autoload colors ;colors)
\r
993 $ echo "$bg[red]$fg[black]${(l:42::-:)}"
\r
995 # Redirect STDERR to a command like xless without redirecting STDOUT as well.
\r
996 $ foo 2>>(xless)
\r
997 # but this executes the command asynchronously. To do it synchronously:
\r
998 $ { { foo 1>&3 } 2>&1 | xless } 3>&1
\r
1000 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3
\r
1001 $ for i in *.mp3; do
\r
1002 > mv $i ${${(C)i}:s/Mp3/mp3/}
\r
1005 # Match file names containing only digits and ending with .xml (require
\r
1006 # *setopt kshglob*)
\r
1007 $ ls -l [0-9]##.xml
\r
1008 $ ls -l <0->.xml
\r
1010 # Remove all "non txt" files
\r
1013 # Move 200 files from a directory into another
\r
1014 $ mv -- *([1,200]) /another/Dir
\r
1016 # Convert images (foo.gif => foo.png):
\r
1017 $ for i in **/*.gif; convert $i $i:r.png
\r
1019 # convert a collection of mp3 files to wave or cdr,
\r
1020 # e.g. file.wav -> file.mp3)
\r
1021 $ for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
\r
1023 # Download with LaTeX2HTML created Files (for example the ZSH-Guide):
\r
1024 $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
\r
1025 > lynx -source $f >${f:t}
\r
1028 # Move all files in dir1 and dir2 that have line counts greater than 10 to
\r
1029 # another directory say "/more10"
\r
1030 $ mv dir[12]/**/*.cr(-.e{'((`wc -l < $REPLY` > 10))'}) /more10
\r
1032 # Make with dpkg a master-list of everyfile that it has installed
\r
1033 $ diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort)
\r
1035 # Replace this fucking Escape-Sequences:
\r
1036 $ autoload colors ; colors
\r
1037 $ print "$bg[cyan]$fg[blue]You are a idiot" >> /dev/pts/3
\r
1039 # Get ASCII value of a character
\r
1040 $ char=N ; print $((#char))
\r
1042 # Filename "Erweiterung"
\r
1043 # Note: The (N) says to use the nullglob option for this particular
\r
1045 $ for i in *.o(N); do
\r
1049 # Rename files; i. e. FOO to foo and bar to BAR
\r
1050 $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'
\r
1051 $ for i in *(.); mv $i ${i:u} # `bar to `BAR'
\r
1053 # Show all suid-files in $PATH
\r
1054 $ ls -latg ${(s.:.)PATH} | grep '^...s'
\r
1055 # or more complex ;)
\r
1056 $ print -l ${^path}/*(Ns,S)
\r
1057 # or show only executables with a user given pattern
\r
1058 $ print -l ${^path}/*vim*(*N)
\r
1060 # gzip files when containing a certain string
\r
1061 $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}
\r
1063 # A small one-liner, that reads from stdin and prints to stdout the first
\r
1064 # unique line i. e. does not print lines that have been printed before
\r
1065 # (this is similar to the unique command, but unique can only handle
\r
1066 # adjacent lines).
\r
1067 $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}
\r
1069 # Lists every executable in PATH
\r
1070 $ print -l ${^path}/*(-*N)
\r
1072 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?
\r
1073 $ ls **/*.c~(*/)#SCCS/*
\r
1075 # List all `README' - files case-insensitive with max. one typo
\r
1076 $ ls **/*(#ia2)readme
\r
1078 # case insensitive checking for variables
\r
1079 $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then
\r
1080 > echo "Penguin on board."
\r
1082 > echo "Not a Linux."
\r
1083 > fi</tt></pre>
\r
1085 <h3 id="_recursive_globbing_examples">(Recursive) Globbing - Examples</h3><div style="clear:left"></div>
\r
1086 <div class="paragraph"><p>A list of valid glob Qualifiers can be found in zshexpn(1). <strong>Note:</strong>
\r
1087 **/ is equivalent to (*/)#! For example:</p></div>
\r
1088 <div class="listingblock">
\r
1089 <div class="content">
\r
1090 <pre><tt>$ print (*/)#zsh_us.ps
\r
1091 zsh-4.2.3/Doc/zsh_us.ps
\r
1092 $ print **/zsh_us.ps
\r
1093 zsh-4.2.3/Doc/zsh_us.ps</tt></pre>
\r
1095 <div class="listingblock">
\r
1096 <div class="content">
\r
1097 <pre><tt># Search for `README' in all Subdirectories
\r
1100 # find directories that contain both "index.php" and "index.html", or in
\r
1101 # general, directories that contain more than one file matching "index.*"
\r
1102 $ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
\r
1104 $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l >= 2 ))':)
\r
1106 # Find command to search for directory name instead of basename
\r
1107 $ print -rl /**/*~^*/path(|/*)
\r
1108 # or - without Zsh
\r
1109 $ find / | grep -e /path/ -e '/path$'
\r
1111 # Print he path of the directories holding the ten biggest C regular files
\r
1112 # in the current directory and subdirectories.
\r
1113 $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
\r
1115 # Find files with size == 0 and send a mail
\r
1116 $ files=(**/*(ND.L0m+0m-2))
\r
1117 > (( $#files > 0 )) && print -rl -- $files | \
\r
1118 mailx -s "empty files" foo@bar.tdl
\r
1121 $ chmod 700 **/(.) # Only files
\r
1122 $ chmod 700 **/(/) # Only directories
\r
1124 # print out all of the files in that directory in 2 columns
\r
1125 $ print -rC2 -- ${1:[...]}/*(D:t)
\r
1126 # ^- number ob columns
\r
1127 # or - if you feel concerned about special characters - use
\r
1128 $ list=(${1:[...]}/*(ND:t))
\r
1129 $ (($#list)) && print -rC2 -- ${(V)list}
\r
1131 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
\r
1132 # (recursive, include dotfiles) remove the setgid/setuid flag and print
\r
1134 $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))
\r
1135 # or with a small script
\r
1136 $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {
\r
1137 > print -r -- $file
\r
1138 > chmod -s $file && print -r fixed $file
\r
1140 # or use ``zargs'' (require autoload zargs) prevent the arg list too
\r
1142 $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
\r
1144 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
\r
1145 $ ls -l foo<23->
\r
1147 # get all files that begin with the date strings from June 4 through
\r
1149 $ ls -l 200406{04..10}*(N)
\r
1150 # or if they are of the form 200406XX (require ``setopt extended_glob''
\r
1151 $ ls -l 200306<4-10>.*
\r
1153 # remove spaces from filenames
\r
1154 $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
\r
1156 # Show only all *.c and *.h - Files
\r
1159 # Show only all *.c - files and ignore `foo.c'
\r
1162 # show data to *really* binary format
\r
1163 $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \
\r
1164 > {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' < binary
\r
1166 # Show only world-readable files
\r
1169 # List files in the current directory are not writable by the owner
\r
1170 $ print -l ~/*(ND.^w)
\r
1172 # find and delete the files which are older than a given parameter
\r
1173 # (seconds/minutes/hours)
\r
1174 # deletes all regular file in /Dir that are older than 3 hours
\r
1175 $ rm -f /Dir/**/*(.mh+3)
\r
1176 # deletes all symlinks in /Dir that are older than 3 minutes
\r
1177 $ rm -f /Dir/**/*(@mm+3)
\r
1178 # deletes all non dirs in /Dir that are older than 30 seconds
\r
1179 $ rm -f /Dir/**/*(ms+30^/)
\r
1180 # deletes all folders, sub-folders and files older than one hour
\r
1181 $ rm ./**/*(.Dmh+1,.DL0)
\r
1182 # deletes all files more than 6 hours old
\r
1183 $ rm -f **/*(mh+6)
\r
1184 # removes all files but the ten newer ones (delete all but last 10
\r
1185 # files in a directory)
\r
1186 $ rm ./*(Om[1,-11])
\r
1187 Note: If you get a arg list too long, you use the builtin rm. For
\r
1189 $ zmodload zsh/files ; rm -f **/*(mh+6)
\r
1190 or use the zargs function:
\r
1191 $ autoload zargs ; zargs **/*(mh+6) -- rm -f
\r
1193 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
\r
1194 # Matching find all files in all subdirectories, searching recursively,
\r
1195 # which have a given name, case insensitive, are at least 50 KB large,
\r
1196 # no more than a week old and owned by the root user, and allowing up
\r
1197 # to a single error in the spelling of the name. In fact, the required
\r
1198 # expression looks like this:
\r
1199 $ ls **/(#ia1)name(LK+50mw-1u0)
\r
1201 # Change the UID from 102 to 666
\r
1202 $ chown 666 **/*(u102)
\r
1204 # List all files which have not been updated since last 10 hours
\r
1205 $ print -rl -- *(Dmh+10^/)
\r
1207 # delete only the oldest file in a directory
\r
1208 $ rm ./*filename*(Om[1])
\r
1210 # Sort the output from `ls -l' by file size
\r
1213 # find most recent file in a directory
\r
1214 $ setopt dotglob ; print directory/**/*(om[1])
\r
1216 # Show only empty files which nor `group' or `world writable'
\r
1219 # Find - and list - the ten newest files in directories and subdirs.
\r
1221 $ print -rl -- **/*(Dom[1,10])
\r
1223 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'').
\r
1224 $ ls -fl *(DOL[1,5])
\r
1226 # Display the 5-10 last modified files.
\r
1227 $ print -rl -- /path/to/dir/**/*(D.om[5,10])
\r
1229 # Find all files without a valid owner.
\r
1230 $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
\r
1232 # Find all the empty directories in a tree.
\r
1233 $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
\r
1234 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
\r
1235 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all
\r
1236 # subdirectories with no entries.
\r
1239 # Remove empty directories afterwards.
\r
1240 $ rmdir ./**/*(/od) 2> /dev/null
\r
1242 # Show only files which are owned by group `users'.
\r
1243 $ ls -l *(G[users])</tt></pre>
\r
1245 <h3 id="_modifiers_usage">Modifiers usage</h3><div style="clear:left"></div>
\r
1246 <div class="paragraph"><p>Modifiers are a powerful mechanism that let you modify the results
\r
1247 returned by parameter, filename and history expansion. See zshexpn(1)
\r
1248 for details.</p></div>
\r
1249 <div class="listingblock">
\r
1250 <div class="content">
\r
1251 <pre><tt># NOTE: Zsh 4.3.4 needed!
\r
1253 # files modified today
\r
1254 $ print *(e:age today now:)
\r
1255 # files modified since 5 pm
\r
1256 $ print *(e-age 17:00 now-)
\r
1257 # ... since 5 o'clock yesterda
\r
1258 $ print *(e-age yesterday,17:00 now-)
\r
1259 # ... from last Christmas before today
\r
1260 $ print *(e-age 2006/12/25 today-)
\r
1261 # ... before yesterday
\r
1262 $ print *(e-age 1970/01/01 yesterday-)
\r
1263 # all files modified between the start of those dates
\r
1264 $ print *(e:age 2006/10/04 2006/10/09:)
\r
1265 # all files modified on that date
\r
1266 $ print *(e:age 2006/10/04:)
\r
1268 $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
\r
1270 # Remove a trailing pathname component, leaving the head. This works like
\r
1275 # Remove all leading pathname components, leaving the tail. This works
\r
1276 # like `basename'.
\r
1280 # Remove the suffix from each file (*.sh in this example)
\r
1281 $f:e is $f file extension
\r
1282 :h --> head (dirname)
\r
1283 :t --> tail (basename)
\r
1284 :r --> rest (extension removed)
\r
1285 $ for f (*.sh) mv $f $f:r
\r
1287 # Remove a filename extension of the form `.xxx', leaving the root name.
\r
1293 # Remove all but the extension.
\r
1300 # Print the new command but do not execute it. Only works with history
\r
1307 # Quote the substituted words, escaping further substitutions.
\r
1314 # Convert the words to all lowercase.
\r
1321 # Convert the words to all uppercase.
\r
1328 # convert 1st char of a word to uppercase
\r
1329 $ foo="one two three four"
\r
1330 $ print -r -- "${(C)foo}"
\r
1331 One Two Three Four</tt></pre>
\r
1333 <h3 id="_redirection_examples">Redirection-Examples</h3><div style="clear:left"></div>
\r
1334 <div class="paragraph"><p>See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))</p></div>
\r
1335 <div class="listingblock">
\r
1336 <div class="content">
\r
1337 <pre><tt># Append `exit 1' at the end of all *.sh - files
\r
1338 $ echo "exit 1" >> *.sh
\r
1340 # adding files to foobar.tar.gz
\r
1341 $ eval set =(gunzip < foobar.tar.gz) '
\r
1342 tar rf $1 additional.txt &&gzip < $1 > foobar.tar.gz'
\r
1344 # Redirect output to a file AND display on screen
\r
1345 $ foobar >&1 > file1 > file2 > ..
\r
1347 # pipe single output to multiple inputs
\r
1348 $ zcat foobar.Z >> (gzip -9 > file1.gz) \
\r
1349 >> (bzip2 -9 > file1.bz2) \
\r
1350 >> (acb --best > file1.acb)
\r
1352 # Append /etc/services at the end of file `foo' and `bar'
\r
1353 $ cat /etc/services >> foo >> bar
\r
1356 $ echo An error >&2 2>&1 | sed -e 's/A/I/'
\r
1358 # send standard output of one process to standard input of several processes
\r
1361 $ process1 > >(process1) > >(process2)
\r
1363 # initializing a variable and simultaneously keeping terminal output
\r
1365 $ { a=$(command >&1 >& 3 3 > &- 2>&1);} 3>&1
\r
1367 # redirect stderr two times
\r
1368 $ setopt multios ; program 2> file2 > file1 2>&1
\r
1370 # Duplicating stdout and stderr to a logfile
\r
1371 $ exec 3>&1 > logfile 2>&2 2>&1 >&3 3>&-
\r
1373 # redirect stderr (only) to a file and to orig. stderr:
\r
1374 $ command 2>&2 2>stderr
\r
1375 # redirect stderr and stdout to separate files and both to orig. stdout:
\r
1376 $ command 2>&1 1>&1 2>stderr 1>stdout
\r
1377 # redirect stderr and stdout to separate files and stdout to orig. stdout
\r
1378 # AND stderr to orig. stderr:
\r
1379 $ command 2>&2 1>&1 2>stderr 1>stdout
\r
1381 # More fun with STDERR ;)
\r
1382 $ ./my-script.sh 2> >(grep -v moron >error.log)|process-output >output.log
\r
1383 $ echo "Thats STDOUT" >>(sed 's/stdout/another example/' > foobar)</tt></pre>
\r
1385 <h3 id="_zmv_examples_require_autoload_zmv">ZMV-Examples (require autoload zmv)</h3><div style="clear:left"></div>
\r
1386 <div class="paragraph"><p><strong>Note:</strong> <em>-n</em> means no execution (just print what would happen). At</p></div>
\r
1387 <div class="listingblock">
\r
1388 <div class="content">
\r
1389 <pre><tt># Remove illegal characters in a fat32 file system. Illegal characters are
\r
1390 # / : ; * ? " < > |
\r
1391 # NOTE: ``-Q'' and (D) is to include hidden files.
\r
1392 $ unwanted='[:;*?\"<>|]'
\r
1393 $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
\r
1395 # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
\r
1396 $ zmv '(*)hell(*)' '${1}heaven${2}'
\r
1398 $ zmv '*' '$f:s/hell/heaven/'
\r
1400 # remove round bracket within filenames
\r
1401 # i. e. foo-(bar).avi -> foo-bar.avi
\r
1402 $ zmv '*' '${f//[()]/}'
\r
1404 # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
\r
1407 1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
\r
1408 $ c=1 zmv '*.foo' '$((c++)).foo'
\r
1410 1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
\r
1412 # Rename "file.with.many.dots.txt" by substituting dots (exept for the last
\r
1413 # one!) with a space
\r
1414 $ touch {1..20}-file.with.many.dots.txt
\r
1415 $ zmv '(*.*)(.*)' '${1//./ }$2'
\r
1417 # Remove the first 4 chars from a filename
\r
1418 $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
\r
1420 # Rename names of all files under the current Dir to lower case, but keep
\r
1422 $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
\r
1424 # replace all 4th character, which is "1", with "2" and so on
\r
1426 $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
\r
1428 # Remove the first 15 characters from a string
\r
1429 $ touch 111111111111111{a-z}
\r
1431 $ zmv '*' '$f[16,-1]'
\r
1433 # Replace spaces (any number of them) with a single dash in file names
\r
1435 $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
\r
1437 $ find . -depth -name '* *' -exec bash -c '
\r
1438 > shopt -s extglob
\r
1440 > dir=${file%/*}
\r
1441 > name=${file##*/}
\r
1442 > newname=${name//*([ -]) *([ -])/-}
\r
1443 > mv -i -- "$file" "$Dir/$newname"' {} {} \;
\r
1445 # Clean up file names and remove special characters
\r
1447 $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
\r
1449 # Add *.py to a bunch of python scripts in a directory (some of them end
\r
1450 # in *.py and give them all a proper extension
\r
1452 $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
\r
1454 # lowercase all extensions (i. e. *.JPG) incl. subfolders
\r
1456 $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
\r
1457 # Or - without Zsh
\r
1458 $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
\r
1462 > *) mv "$f" "${f%.*}.jpg" ;
\r
1466 # remove leading zeros from file extension
\r
1469 filename.001 filename.003 filename.005 filename.007 filename.009
\r
1470 filename.002 filename.004 filename.006 filename.008 filename.010
\r
1471 $ zmv '(filename.)0##(?*)' '$1$2'
\r
1473 filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
\r
1478 foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
\r
1479 $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
\r
1481 foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
\r
1483 # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
\r
1485 $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
\r
1487 # See above, but now only files with a filename >= 30 chars
\r
1489 $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
\r
1491 # Replace spaces in filenames with a underline
\r
1493 $ zmv '* *' '$f:gs/ /_'
\r
1495 # Change the suffix from *.sh to *.pl
\r
1497 $ zmv -W '*.sh' '*.pl'
\r
1499 # Add a "".txt" extension to all the files within ${HOME}
\r
1500 # ``-.'' is to only rename regular files or symlinks to regular files,
\r
1501 # ``D'' is to also rename hidden files (dotfiles))
\r
1503 $ zmv -Q '/home/**/*(D-.)' '$f.txt'
\r
1504 # Or to only rename files that don't have an extension:
\r
1505 $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
\r
1507 # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
\r
1509 $ chars='[][?=+<>;",*-]'
\r
1510 $ zmv '(**/)(*)' '$1${2//$~chars/%}'
\r
1512 # Removing single quote from filenames (recursively)
\r
1514 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1516 # When a new file arrives (named file.txt) rename all files in order to
\r
1517 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
\r
1518 # file119.txt and so on ending with file.txt becoming file1.txt
\r
1520 $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
\r
1522 # lowercase/uppercase all files/directories
\r
1524 $ zmv '(*)' '${(L)1}' # lowercase
\r
1525 $ zmv '(*)' '${(U)1}' # uppercase
\r
1527 # Remove the suffix *.c from all C-Files
\r
1529 $ zmv '(*).c' '$1'
\r
1531 # Uppercase only the first letter of all *.mp3 - files
\r
1533 $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
\r
1535 # Copy the target `README' in same directory as each `Makefile'
\r
1537 $ zmv -C '(**/)Makefile' '${1}README'
\r
1539 # Removing single quote from filenames (recursively)
\r
1541 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1543 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
\r
1545 $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
\r
1546 $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively</tt></pre>
\r
1548 <h3 id="_module_examples">Module-Examples</h3><div style="clear:left"></div>
\r
1549 <div class="paragraph"><p>Please read zshmodules(1) first!</p></div>
\r
1550 <h4 id="_zsh_pcre_require_zmodload_zsh_pcre">zsh/pcre (require zmodload zsh/pcre)</h4>
\r
1551 <div class="listingblock">
\r
1552 <div class="content">
\r
1553 <pre><tt># Copy files of a certain period (date indicated in the filenames)
\r
1554 $ zmodload zsh/pcre
\r
1555 $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)
\r
1557 $ m() { [[ $1 -pcre-match pcre-regexp ]] }
\r
1558 $ ls -d -- *(+m)</tt></pre>
\r
1560 <h4 id="_zsh_clone_require_zmodload_zsh_clone">zsh/clone (require zmodload zsh/clone)</h4>
\r
1561 <div class="listingblock">
\r
1562 <div class="content">
\r
1563 <pre><tt># Creates a forked instance of the current shell ($! is set to zero) and
\r
1564 # execute ``command'' on /dev/tty8 (for this example).
\r
1565 $ zmodload zsh/clone
\r
1566 $ clone /dev/tty8 && (($! == 0)) && exec command</tt></pre>
\r
1568 <h4 id="_zsh_datetime_require_zmodload_zsh_datetime">zsh/datetime (require zmodload zsh/datetime)</h4>
\r
1569 <div class="listingblock">
\r
1570 <div class="content">
\r
1571 <pre><tt> $ zmodload zsh/datetime
\r
1572 $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'
\r
1573 $ export DATE=`datereplacement`
\r
1576 # strip date from filename
\r
1577 $ $ zmodload zsh/datetime
\r
1578 $ setopt extendedglob
\r
1579 $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat
\r
1580 $ strftime -s pattern \
\r
1581 '???_???_<0-%Y%m%d>_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))
\r
1582 $ print -rl -- $~pattern
\r
1583 aaa_bbb_20041212_c.dat
\r
1584 $ print -rl -- $pattern
\r
1585 ???_???_<0-20050815>_?.dat
\r
1587 # Search files size == 0, to be based on the file name containing a date
\r
1588 # rather than the "last modified" date of the file
\r
1589 $ zmodload -i zsh/datetime
\r
1590 $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
\r
1591 $ files=(**/$file(N.L0))
\r
1592 $ (( $#files > 0 )) && print -rl -- $files | \
\r
1593 mailx -s "empty files" foo@bar.tdl</tt></pre>
\r
1595 <h4 id="_zsh_stat_require_zmodload_zsh_stat">zsh/stat (require zmodload zsh/stat)</h4>
\r
1596 <div class="listingblock">
\r
1597 <div class="content">
\r
1598 <pre><tt># test if a symbolic link links to a certain file
\r
1599 $ zmodload -i zsh/stat
\r
1600 $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln
\r
1602 # comparing file dates
\r
1603 $ zmodload zsh/stat
\r
1606 $ touch bar & sleep 5 & touch foo
\r
1607 $ echo $file1 is $(($(stat +mtime $file2) - \
\r
1608 $(stat +mtime $file1))) seconds older than $file2.
\r
1609 bar is 5 seconds older than foo
\r
1611 # list the files of a disk smaller than some other file
\r
1612 $ zmodload zsh/stat
\r
1613 $ stat -A max +size some-other-file
\r
1614 $ print -rl ./**/*(D.L-$max)
\r
1616 # List the top 100 biggest files in a disk
\r
1617 $ zmodload zsh/stat
\r
1618 $ ls -fld ./**/*(d`stat +device .`OL[1,100])
\r
1620 # Get only the user name and the file names from (like
\r
1621 # ls -l * | awk '{print $3" " $8}')
\r
1622 $ zmodload zsh/stat
\r
1624 > stat -sA user +uid -- "$file" &&
\r
1625 > print -r -- "$user" "$file"
\r
1628 # get the difference between actual bytes of file and allocated bytes of file
\r
1629 $ zmodload zsh/stat
\r
1630 $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))
\r
1632 # Find largest file
\r
1633 # ``D'' : to include dot files (d lowercase is for device)
\r
1634 # ``O'' : reverse Ordered (o lowercase for non-reverse order)
\r
1635 # ``L'' : by file Length (l is for number of links)
\r
1636 # ``[1]'': return only first one
\r
1637 $ zmodload zsh/stat
\r
1638 $ stat +size ./*(DOL[1])
\r
1640 # file size in bytes
\r
1641 $ zmodload zsh/stat
\r
1642 $ stat -L +size ~/.zshrc
\r
1645 # Delete files in a directory that hasn't been accessed in the last ten days
\r
1646 # and send ONE mail to the owner of the files informing him/her of the files'
\r
1648 $ zmodload zsh/stat zsh/files
\r
1649 $ typeset -A f; f=()
\r
1650 $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
\r
1651 $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
\r
1653 # Get a "ls -l" on all the files in the tree that are younger than a
\r
1655 $ zmodload zsh/stat
\r
1656 $ for d (. ./**/*(N/m-2))
\r
1657 > print -r -- $'\n'$d: && cd $d && {
\r
1658 > for f (*(Nm-2om))
\r
1659 > stat -F '%b %d %H:%M' -LsAs -- $f &&
\r
1660 > print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \
\r
1661 > ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]}
\r
1665 # get file creation date
\r
1666 $ zmodload zsh/stat
\r
1667 $ stat -F '%d %m %Y' +mtime ~/.zshrc
\r
1669 $ stat -F '%D' +mtime ~/.zshrc
\r
1670 06/30/04</tt></pre>
\r
1672 <h4 id="_zsh_files_require_zmodload_zsh_files">zsh/files (require zmodload zsh/files)</h4>
\r
1673 <div class="listingblock">
\r
1674 <div class="content">
\r
1675 <pre><tt># search a directory for files containing a certain string then copy those
\r
1676 # files to another directory.
\r
1677 $ zmodload zsh/files
\r
1679 $ cp $(grep -lZr foobar .) otherdirectory</tt></pre>
\r
1681 <h4 id="_zsh_mapfile_require_zmodload_zsh_mapfile">zsh/mapfile (require zmodload zsh/mapfile)</h4>
\r
1682 <div class="listingblock">
\r
1683 <div class="content">
\r
1684 <pre><tt># grepping for two patterns
\r
1685 $ zmodload zsh/mapfile
\r
1687 $ pattern2="bar foo"
\r
1688 $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] && [[ $z = *$pattern1* && \
\r
1689 $z = *$pattern2* ]]'})
\r
1690 # or a solution in combination with zsh/pcre
\r
1691 $ zmodload -i zsh/mapfile zsh/pcre
\r
1693 $ pattern2="bar foo"
\r
1694 $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"
\r
1696 $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})
\r
1698 # equivalent for ``less /etc/passwd | grep -v root''
\r
1699 $ zmodload zsh/mapfile
\r
1701 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}
\r
1702 # or - for case insensitive
\r
1703 $ setopt extendedglob
\r
1704 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
\r
1706 # If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
\r
1707 # this empty tags (ones ending in '/>') so if encountered in the same
\r
1708 # order, the preceeding tags would become ``<TAGA/>1</TAGA>'' and
\r
1709 # ``<TAGB/>2</TAGB>''
\r
1710 $ zmodload zsh/mapfile
\r
1712 $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\
\r
1713 > (#im)<TAGA>*<\/TAGA>/<TAGA>$((++cnt))<\/TAGA>}
\r
1715 # removing all files in users Maildir/new that contain ``filename="gone.src''
\r
1716 $ zmodload zsh/{files,mapfile}
\r
1717 $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \
\r
1718 *filename=\"gone.scr\"* ]]'})
\r
1720 # Grep out the Title from a postscript file and append that value to the
\r
1721 # end of the filename
\r
1723 $ zmodload zsh/mapfile
\r
1724 $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'</tt></pre>
\r
1726 <h4 id="_zsh_mathfunc_require_zmodload_zsh_mathfunc">zsh/mathfunc (require zmodload zsh/mathfunc)</h4>
\r
1727 <div class="listingblock">
\r
1728 <div class="content">
\r
1729 <pre><tt>$ zmodload zsh/mathfunc
\r
1730 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
\r
1731 -1.1102230246251565e-16
\r
1732 $ echo $(( pi = 4.0 * atan(1.0) ))
\r
1733 3.1415926535897931
\r
1734 $ echo $(( f = sin(0.3) ))
\r
1735 0.29552020666133955
\r
1736 $ print $((1e12 * rand48()))
\r
1737 847909677310.23413
\r
1738 $ print $(( rand48(seed) ))
\r
1739 0.01043488334700271</tt></pre>
\r
1741 <h4 id="_zsh_termcap_require_zmodload_zsh_termcap">zsh/termcap (require zmodload zsh/termcap)</h4>
\r
1742 <div class="listingblock">
\r
1743 <div class="content">
\r
1744 <pre><tt> $ zmodload -ab zsh/termcap echotc
\r
1745 $ GREEN=`echotc AF 2`
\r
1746 $ YELLOW=`echotc AF 3`
\r
1747 $ RED=`echotc AF 1`
\r
1748 $ BRIGHTRED=`echotc md ; echotc AF 1`
\r
1749 $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred</tt></pre>
\r
1751 <h4 id="_zsh_zpty_require_zmodload_zsh_zpty">zsh/zpty (require zmodload zsh/zpty)</h4>
\r
1752 <div class="listingblock">
\r
1753 <div class="content">
\r
1754 <pre><tt> $ zmodload zsh/zpty
\r
1755 $ zpty PW passwd $1
\r
1756 $ zpty PW passwd $1
\r
1757 # ``-r'': read the output of the command name.
\r
1758 # ``z'' : Parameter
\r
1759 $ zpty -r PW z '*password:'
\r
1760 # send the to command name the given strings as input
\r
1762 $ zpty -r PW z '*password:'
\r
1764 # The second form, with the -d option, is used to delete commands
\r
1765 # previously started, by supplying a list of their names. If no names
\r
1766 # are given, all commands are deleted. Deleting a command causes the HUP
\r
1767 # signal to be sent to the corresponding process.
\r
1768 $ zpty -d PW</tt></pre>
\r
1770 <h4 id="_zsh_net_socket_require_zmodload_zsh_net_socket">zsh/net/socket (require zmodload zsh/net/socket)</h4>
\r
1771 <div class="listingblock">
\r
1772 <div class="content">
\r
1773 <pre><tt># ``-l'': open a socket listening on filename
\r
1774 # ``-d'': argument will be taken as the target file descriptor for the
\r
1776 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''
\r
1777 # (3.7.2: File descriptors)
\r
1778 $ zmodload zsh/net/socket
\r
1780 # ``-a'': accept an incoming connection to the socket
\r
1781 $ zsocket -a -d 4 3
\r
1782 $ zsocket -a -d 5 3 # accept a connection
\r
1783 $ echo foobar >&4
\r
1784 $ echo barfoo >&5
\r
1785 $ 4>&- 5>&- 3>&</tt></pre>
\r
1787 <h4 id="_zsh_zftp_require_zmodload_zsh_zftp">zsh/zftp (require zmodload zsh/zftp)</h4>
\r
1788 <div class="listingblock">
\r
1789 <div class="content">
\r
1790 <pre><tt> $ autoload -U zfinit
\r
1792 $ zfparams www.example.invalid myuserid mypassword
\r
1795 $ zfls -l zshtips.html
\r
1796 $ zfput zshtips.html
\r
1797 $ zfls -l zshtips.html
\r
1799 # Automatically transfer files using FTP with error checking
\r
1800 $ autoload -U zfinit ; zfinit
\r
1801 $ zftp open host.name.invalid user passwd || exit
\r
1802 $ zftp get /remote/file > /local/file; r=$?
\r
1803 $ zftp close && exit r
\r
1805 # compress and ftp on the fly
\r
1806 $ autoload -U zfinit ; zfinit
\r
1807 $ zftp open host.name.invalid user password
\r
1808 $ zftp get $file | bzip2 > ${file}.bz2
\r
1811 # Recursice ``get''
\r
1812 $ autoload -U zfinit ; zfinit
\r
1814 $ zfcd daemontools
\r
1815 $ for file in `zfls` ; do
\r
1820 # Upload all regular files in $HOME/foobar (recursive) that are newer than
\r
1821 # two hours to ftp.foobar.invalid/path/to/upload
\r
1822 $ autoload -U zfinit ; zfinit
\r
1823 $ zfopen ftp.foobar.invalid/path/to/upload
\r
1825 $ zfput -r **/*(.mh-2)
\r
1828 # long list of files on a ftp
\r
1829 $ autoload -U zfinit ; zfinit
\r
1830 $ zfopen some-host
\r
1831 $ zfcd /some/remote/Dir
\r
1832 $ cd /some/local/Dir
\r
1833 # If the list.txt is located on the remote host, change to
\r
1834 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}
\r
1835 $ zfget ${(f)"$(cat list.txt)"}
\r
1836 $ zfclose</tt></pre>
\r
1838 <h4 id="_zsh_zselect_require_zmodload_zsh_zselect">zsh/zselect (require zmodload zsh/zselect)</h4>
\r
1839 <div class="listingblock">
\r
1840 <div class="content">
\r
1841 <pre><tt># It's similar to
\r
1844 | $ stty -icanon min 0 time 50
\r
1847 | $ case "$yesno" in
\r
1848 | > yes) command1;;
\r
1849 | > *) command2;;
\r
1852 $ zmodload zsh/zselect
\r
1853 $ if zselect -t 500 -r 0 && read yesno && [ yes = "$yesno" ]; then
\r
1857 > fi</tt></pre>
\r
1860 <h2 id="_options">OPTIONS</h2>
\r
1861 <div class="sectionbody">
\r
1862 <h3 id="_navigation_options">Navigation options</h3><div style="clear:left"></div>
\r
1863 <div class="paragraph"><p><strong>auto_cd</strong> (allow one to change to a directory by entering it as a
\r
1864 command). <strong>auto_pushd</strong> (automatically append dirs to the push/pop list)
\r
1865 pushd_ignore_dups (and don’t duplicate them).</p></div>
\r
1866 <h3 id="_misc">Misc</h3><div style="clear:left"></div>
\r
1867 <div class="paragraph"><p><strong>no_hup</strong> (don’t send HUP signal to background jobs when exiting ZSH).
\r
1868 <strong>print_exit_value</strong> (show a message with the exit code when a command
\r
1869 returns with a non-zero exit code)</p></div>
\r
1870 <h4 id="_history_options">History options</h4>
\r
1871 <div class="paragraph"><p><strong>hist_verify</strong> (let the user edit the command line after history
\r
1872 expansion (e.g. !ls) instead of immediately running it)<br />
\r
1873 Use the same history file for all sessions :<br />
\r
1874 <strong>setopt SHARE_HISTORY</strong></p></div>
\r
1875 <h4 id="_privacy_security">Privacy / Security</h4>
\r
1876 <div class="paragraph"><p><strong>no_clobber</strong> (or set -C; prevent <em>></em> redirection from truncating
\r
1877 the given file if it already exists)</p></div>
\r
1878 <h4 id="_spelling_correction">Spelling correction</h4>
\r
1879 <div class="paragraph"><p><strong>correct</strong> (automatically correct the spelling of commands).
\r
1880 <strong>correct_all</strong> (automatically correct the spelling of each word on the
\r
1881 command line) <strong>dvorak</strong> (dvorak layout)</p></div>
\r
1883 <h2 id="_unsorted_misc">UNSORTED/MISC</h2>
\r
1884 <div class="sectionbody">
\r
1885 <div class="paragraph"><p>Mailpath: simple multiple mailpath:</p></div>
\r
1886 <div class="listingblock">
\r
1887 <div class="content">
\r
1888 <pre><tt>mailpath=($HOME/Mail/mbox'?new mail in mbox'
\r
1889 $HOME/Mail/tux.u-strasbg'?new mail in tux'
\r
1890 $HOME/Mail/lilo'?new mail in lilo'
\r
1891 $HOME/Mail/ldap-fr'?new mail in ldap-fr')</tt></pre>
\r
1893 <div class="paragraph"><p>Mailpath: dynamic mailpath:</p></div>
\r
1894 <div class="listingblock">
\r
1895 <div class="content">
\r
1896 <pre><tt>typeset -a mailpath
\r
1897 for i in ~/Mail/Lists/*(.); do
\r
1898 mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."
\r
1901 <div class="paragraph"><p>Avoid globbing on special commands:</p></div>
\r
1902 <div class="listingblock">
\r
1903 <div class="content">
\r
1904 <pre><tt>for com in alias expr find mattrib mcopy mdir mdel which;
\r
1905 alias $com="noglob $com"</tt></pre>
\r
1907 <div class="paragraph"><p>For migrating your bashprompt to zsh use the script bash2zshprompt located in
\r
1908 the zsh source distribution under <em>Misc</em>.</p></div>
\r
1909 <div class="paragraph"><p>For migration from (t)csh to zsh use the c2z tool that converts csh
\r
1910 aliases and environment and shell variables to zsh. It does this by running
\r
1911 csh, and having csh report on aliases and variables. The script then converts
\r
1912 these to zsh startup files. It has some issues and usage information that are
\r
1913 documented at the top of this script.</p></div>
\r
1914 <div class="paragraph"><p>Here are functions to set the title and hardstatus of an <strong>XTerm</strong> or of <strong>GNU
\r
1915 Screen</strong> to <em>zsh</em> and the current directory, respectively, when the prompt is
\r
1916 displayed, and to the command name and rest of the command line, respectively,
\r
1917 when a command is executed:</p></div>
\r
1918 <div class="listingblock">
\r
1919 <div class="content">
\r
1920 <pre><tt>function title {
\r
1921 if [[ $TERM == "screen" ]]; then
\r
1922 # Use these two for GNU Screen:
\r
1923 print -nR $' 33k'$1$' 33'\
\r
1924 print -nR $' 33]0;'$2$''
\r
1925 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
\r
1926 # Use this one instead for XTerms:
\r
1927 print -nR $' 33]0;'$*$''
\r
1930 function precmd { title zsh "$PWD" }
\r
1931 function preexec {
\r
1933 local -a cmd; cmd=(${(z)1})
\r
1934 title $cmd[1]:t "$cmd[2,-1]"
\r
1937 <div class="paragraph"><p>Put the following line into your ~/.screenrc to see this fancy hardstatus:</p></div>
\r
1938 <div class="listingblock">
\r
1939 <div class="content">
\r
1940 <pre><tt>caption always "%3n %t%? (%u)%?%?: %h%?"</tt></pre>
\r
1942 <div class="paragraph"><p>Special variables which are assigned:</p></div>
\r
1943 <div class="listingblock">
\r
1944 <div class="content">
\r
1945 <pre><tt>$LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID
\r
1946 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath</tt></pre>
\r
1949 <h2 id="_links">LINKS</h2>
\r
1950 <div class="sectionbody">
\r
1951 <div class="dlist"><dl>
\r
1952 <dt class="hdlist1">
\r
1957 <strong><a href="http://www.zsh.org/">http://www.zsh.org/</a></strong>
\r
1960 <dt class="hdlist1">
\r
1965 <strong><a href="http://sourceforge.net/projects/zsh/">http://sourceforge.net/projects/zsh/</a></strong>
\r
1968 <dt class="hdlist1">
\r
1969 Z shell page at sunsite.dk
\r
1973 <strong><a href="http://zsh.sunsite.dk/">http://zsh.sunsite.dk/</a></strong>
\r
1976 <dt class="hdlist1">
\r
1977 From Bash to Z Shell: Conquering the Command Line - the book
\r
1981 <strong><a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a></strong>
\r
1984 <dt class="hdlist1">
\r
1985 "Zsh - die magische Shell" (german book about Zsh) by Sven Guckes and Julius Plenz
\r
1989 <strong><a href="http://zshbuch.org/">http://zshbuch.org/</a></strong>
\r
1992 <dt class="hdlist1">
\r
1993 Mailinglistarchive
\r
1997 <strong><a href="http://www.zsh.org/mla/">http://www.zsh.org/mla/</a></strong>
\r
2000 <dt class="hdlist1">
\r
2005 <strong><a href="http://zsh.dotsrc.org/FAQ/">http://zsh.dotsrc.org/FAQ/</a></strong>
\r
2008 <dt class="hdlist1">
\r
2013 <strong><a href="http://zsh.sunsite.dk/Guide/">http://zsh.sunsite.dk/Guide/</a></strong>
\r
2016 <dt class="hdlist1">
\r
2021 <strong><a href="http://zshwiki.org/home/">http://zshwiki.org/home/</a></strong>
\r
2024 <dt class="hdlist1">
\r
2025 A short introduction from BYU
\r
2029 <strong><a href="http://docs.cs.byu.edu/linux/advanced/zsh.html">http://docs.cs.byu.edu/linux/advanced/zsh.html</a></strong>
\r
2032 <dt class="hdlist1">
\r
2037 <strong><a href="http://stchaz.free.fr/mouse.zsh">http://stchaz.free.fr/mouse.zsh</a></strong>
\r
2040 <dt class="hdlist1">
\r
2041 Curtains up: introducing the Z shell
\r
2045 <strong><a href="http://www-128.ibm.com/developerworks/linux/library/l-z.html?dwzone=linux">http://www-128.ibm.com/developerworks/linux/library/l-z.html?dwzone=linux</a></strong>
\r
2048 <dt class="hdlist1">
\r
2049 ZSH-Liebhaberseite (german)
\r
2053 <strong><a href="http://michael-prokop.at/computer/tools_zsh_liebhaber.html">http://michael-prokop.at/computer/tools_zsh_liebhaber.html</a></strong>
\r
2056 <dt class="hdlist1">
\r
2057 ZSH-Seite von Michael Prokop (german)
\r
2061 <strong><a href="http://michael-prokop.at/computer/tools_zsh.html">http://michael-prokop.at/computer/tools_zsh.html</a></strong>
\r
2064 <dt class="hdlist1">
\r
2065 ZSH Prompt introduction
\r
2069 <strong><a href="http://aperiodic.net/phil/prompt/">http://aperiodic.net/phil/prompt/</a></strong>
\r
2072 <dt class="hdlist1">
\r
2073 ft’s zsh configuration
\r
2077 <strong><a href="http://ft.bewatermyfriend.org/comp/zsh.html">http://ft.bewatermyfriend.org/comp/zsh.html</a></strong>
\r
2080 <dt class="hdlist1">
\r
2081 Adam’s ZSH page
\r
2085 <strong><a href="http://www.adamspiers.org/computing/zsh/">http://www.adamspiers.org/computing/zsh/</a></strong>
\r
2088 <dt class="hdlist1">
\r
2089 Zzappers Best of ZSH Tips
\r
2093 <strong><a href="http://www.rayninfo.co.uk/tips/zshtips.html">http://www.rayninfo.co.uk/tips/zshtips.html</a></strong>
\r
2096 <dt class="hdlist1">
\r
2097 Zsh Webpage by Christian Schneider
\r
2101 <strong><a href="http://www.strcat.de/zsh/">http://www.strcat.de/zsh/</a></strong>
\r
2104 <dt class="hdlist1">
\r
2105 The zsh-lovers webpage
\r
2109 <strong><a href="http://grml.org/zsh/">http://grml.org/zsh/</a></strong>
\r
2112 <dt class="hdlist1">
\r
2117 <strong>#zsh at irc.freenode.org</strong>
\r
2120 <dt class="hdlist1">
\r
2121 The Z shell reference-card (included in the zsh-lovers debian-package)
\r
2125 <strong><a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a></strong>
\r
2130 <h2 id="_authors">AUTHORS</h2>
\r
2131 <div class="sectionbody">
\r
2132 <div class="paragraph"><p>This manpage was written by Michael Prokop, Christian <em>strcat</em>
\r
2133 Schneider and Matthias Kopfermann. But many ideas have been taken from
\r
2134 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),
\r
2135 google, newsgroups and the zsh-Wiki.<br />
\r
2136 Thanks for your cool and incredible tips. We learned much from you!</p></div>
\r
2137 <div class="paragraph"><p>In alphabetic order:</p></div>
\r
2138 <div class="listingblock">
\r
2139 <div class="content">
\r
2140 <pre><tt>Andrew 'zefram' Main - http://www.fysh.org/~zefram/
\r
2141 Barton E. Schaefer - http://www.well.com/user/barts/
\r
2142 Matthias Kopfermann - http://www.infodrom.north.de/~matthi/
\r
2143 Oliver Kiddle - http://people.freenet.de/opk/
\r
2144 Paul Falstad - http://www.falstad.com/
\r
2145 Peter Stephenson - http://homepage.ntlworld.com/p.w.stephenson/
\r
2147 Stephane Chazelas - http://stephane.chazelas.free.fr/
\r
2148 Sven Guckes - http://www.guckes.net/
\r
2149 Sven Wischnowsky - http://w9y.de/zsh/zshrc</tt></pre>
\r
2152 <h2 id="_see_also">SEE ALSO</h2>
\r
2153 <div class="sectionbody">
\r
2154 <div class="paragraph"><p>Manpages of zsh:</p></div>
\r
2155 <div class="listingblock">
\r
2156 <div class="content">
\r
2157 <pre><tt> zsh Zsh overview
\r
2158 zshall Tthe Z shell meta-man page
\r
2159 zshbuiltins Zsh built-in commands
\r
2160 zshcalsys zsh calendar system
\r
2161 zshcompctl zsh programmable completion
\r
2162 zshcompsys Zsh completion system
\r
2163 zshcompwid Zsh completion widgets
\r
2164 zshcontrib User contributions to zsh
\r
2165 zshexpn Zsh expansion and substitution
\r
2166 zshmisc Anything not fitting into the other sections
\r
2167 zshmodules Zsh loadable modules
\r
2168 zshoptions Zsh options
\r
2169 zshparam Zsh parameters
\r
2170 zshroadmap Informal introduction to the zsh manual
\r
2171 zshtcpsys Zsh tcp system
\r
2172 zshzle Zsh command line editing
\r
2173 zshzftpsys Zsh built-in FTP client
\r
2174 zshall Meta-man page containing all of the above</tt></pre>
\r
2176 <div class="paragraph"><p>Note: especially <em>man zshcontrib</em> covers very useful topics!<br />
\r
2177 Book: <strong>From Bash to Z Shell</strong> by Oliver Kiddle, Jerry Peck and Peter
\r
2178 Stephenson. <strong>ISBN: 1590593766</strong>. - <strong><a href="http://www.bash2zsh.com/">bash2zsh.com</a></strong><br />
\r
2179 Also take a look at the section <strong>LINKS</strong> in this manpage.</p></div>
\r
2181 <h2 id="_bugs">BUGS</h2>
\r
2182 <div class="sectionbody">
\r
2183 <div class="paragraph"><p>Probably. This manpage might be never complete. So please report bugs,
\r
2184 feedback and suggestions to <<a href="mailto:zsh-lovers@michael-prokop.at">zsh-lovers@michael-prokop.at</a>>. Thank
\r
2187 <h2 id="_copyright">COPYRIGHT</h2>
\r
2188 <div class="sectionbody">
\r
2189 <div class="paragraph"><p>Copyright (C) Michael Prokop, Christian Schneider and Matthias
\r
2190 Kopfermann.</p></div>
\r
2193 <div id="footnotes"><hr /></div>
\r
2195 <div id="footer-text">
\r
2196 Last updated 2010-07-28 17:55:37 EDT
\r