Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / zsh / zsh-lovers.html
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
4 <head>\r
5 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 8.6.9" />\r
7 <title>ZSH-LOVERS(1)</title>\r
8 <style type="text/css">\r
9 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */\r
10 \r
11 /* Default font. */\r
12 body {\r
13   font-family: Georgia,serif;\r
14 }\r
15 \r
16 /* Title font. */\r
17 h1, h2, h3, h4, h5, h6,\r
18 div.title, caption.title,\r
19 thead, p.table.header,\r
20 #toctitle,\r
21 #author, #revnumber, #revdate, #revremark,\r
22 #footer {\r
23   font-family: Arial,Helvetica,sans-serif;\r
24 }\r
25 \r
26 body {\r
27   margin: 1em 5% 1em 5%;\r
28 }\r
29 \r
30 a {\r
31   color: blue;\r
32   text-decoration: underline;\r
33 }\r
34 a:visited {\r
35   color: fuchsia;\r
36 }\r
37 \r
38 em {\r
39   font-style: italic;\r
40   color: navy;\r
41 }\r
42 \r
43 strong {\r
44   font-weight: bold;\r
45   color: #083194;\r
46 }\r
47 \r
48 h1, h2, h3, h4, h5, h6 {\r
49   color: #527bbd;\r
50   margin-top: 1.2em;\r
51   margin-bottom: 0.5em;\r
52   line-height: 1.3;\r
53 }\r
54 \r
55 h1, h2, h3 {\r
56   border-bottom: 2px solid silver;\r
57 }\r
58 h2 {\r
59   padding-top: 0.5em;\r
60 }\r
61 h3 {\r
62   float: left;\r
63 }\r
64 h3 + * {\r
65   clear: left;\r
66 }\r
67 h5 {\r
68   font-size: 1.0em;\r
69 }\r
70 \r
71 div.sectionbody {\r
72   margin-left: 0;\r
73 }\r
74 \r
75 hr {\r
76   border: 1px solid silver;\r
77 }\r
78 \r
79 p {\r
80   margin-top: 0.5em;\r
81   margin-bottom: 0.5em;\r
82 }\r
83 \r
84 ul, ol, li > p {\r
85   margin-top: 0;\r
86 }\r
87 ul > li     { color: #aaa; }\r
88 ul > li > * { color: black; }\r
89 \r
90 .monospaced, code, pre {\r
91   font-family: "Courier New", Courier, monospace;\r
92   font-size: inherit;\r
93   color: navy;\r
94   padding: 0;\r
95   margin: 0;\r
96 }\r
97 pre {\r
98   white-space: pre-wrap;\r
99 }\r
100 \r
101 #author {\r
102   color: #527bbd;\r
103   font-weight: bold;\r
104   font-size: 1.1em;\r
105 }\r
106 #email {\r
107 }\r
108 #revnumber, #revdate, #revremark {\r
109 }\r
110 \r
111 #footer {\r
112   font-size: small;\r
113   border-top: 2px solid silver;\r
114   padding-top: 0.5em;\r
115   margin-top: 4.0em;\r
116 }\r
117 #footer-text {\r
118   float: left;\r
119   padding-bottom: 0.5em;\r
120 }\r
121 #footer-badges {\r
122   float: right;\r
123   padding-bottom: 0.5em;\r
124 }\r
125 \r
126 #preamble {\r
127   margin-top: 1.5em;\r
128   margin-bottom: 1.5em;\r
129 }\r
130 div.imageblock, div.exampleblock, div.verseblock,\r
131 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
132 div.admonitionblock {\r
133   margin-top: 1.0em;\r
134   margin-bottom: 1.5em;\r
135 }\r
136 div.admonitionblock {\r
137   margin-top: 2.0em;\r
138   margin-bottom: 2.0em;\r
139   margin-right: 10%;\r
140   color: #606060;\r
141 }\r
142 \r
143 div.content { /* Block element content. */\r
144   padding: 0;\r
145 }\r
146 \r
147 /* Block element titles. */\r
148 div.title, caption.title {\r
149   color: #527bbd;\r
150   font-weight: bold;\r
151   text-align: left;\r
152   margin-top: 1.0em;\r
153   margin-bottom: 0.5em;\r
154 }\r
155 div.title + * {\r
156   margin-top: 0;\r
157 }\r
158 \r
159 td div.title:first-child {\r
160   margin-top: 0.0em;\r
161 }\r
162 div.content div.title:first-child {\r
163   margin-top: 0.0em;\r
164 }\r
165 div.content + div.title {\r
166   margin-top: 0.0em;\r
167 }\r
168 \r
169 div.sidebarblock > div.content {\r
170   background: #ffffee;\r
171   border: 1px solid #dddddd;\r
172   border-left: 4px solid #f0f0f0;\r
173   padding: 0.5em;\r
174 }\r
175 \r
176 div.listingblock > div.content {\r
177   border: 1px solid #dddddd;\r
178   border-left: 5px solid #f0f0f0;\r
179   background: #f8f8f8;\r
180   padding: 0.5em;\r
181 }\r
182 \r
183 div.quoteblock, div.verseblock {\r
184   padding-left: 1.0em;\r
185   margin-left: 1.0em;\r
186   margin-right: 10%;\r
187   border-left: 5px solid #f0f0f0;\r
188   color: #888;\r
189 }\r
190 \r
191 div.quoteblock > div.attribution {\r
192   padding-top: 0.5em;\r
193   text-align: right;\r
194 }\r
195 \r
196 div.verseblock > pre.content {\r
197   font-family: inherit;\r
198   font-size: inherit;\r
199 }\r
200 div.verseblock > div.attribution {\r
201   padding-top: 0.75em;\r
202   text-align: left;\r
203 }\r
204 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */\r
205 div.verseblock + div.attribution {\r
206   text-align: left;\r
207 }\r
208 \r
209 div.admonitionblock .icon {\r
210   vertical-align: top;\r
211   font-size: 1.1em;\r
212   font-weight: bold;\r
213   text-decoration: underline;\r
214   color: #527bbd;\r
215   padding-right: 0.5em;\r
216 }\r
217 div.admonitionblock td.content {\r
218   padding-left: 0.5em;\r
219   border-left: 3px solid #dddddd;\r
220 }\r
221 \r
222 div.exampleblock > div.content {\r
223   border-left: 3px solid #dddddd;\r
224   padding-left: 0.5em;\r
225 }\r
226 \r
227 div.imageblock div.content { padding-left: 0; }\r
228 span.image img { border-style: none; vertical-align: text-bottom; }\r
229 a.image:visited { color: white; }\r
230 \r
231 dl {\r
232   margin-top: 0.8em;\r
233   margin-bottom: 0.8em;\r
234 }\r
235 dt {\r
236   margin-top: 0.5em;\r
237   margin-bottom: 0;\r
238   font-style: normal;\r
239   color: navy;\r
240 }\r
241 dd > *:first-child {\r
242   margin-top: 0.1em;\r
243 }\r
244 \r
245 ul, ol {\r
246     list-style-position: outside;\r
247 }\r
248 ol.arabic {\r
249   list-style-type: decimal;\r
250 }\r
251 ol.loweralpha {\r
252   list-style-type: lower-alpha;\r
253 }\r
254 ol.upperalpha {\r
255   list-style-type: upper-alpha;\r
256 }\r
257 ol.lowerroman {\r
258   list-style-type: lower-roman;\r
259 }\r
260 ol.upperroman {\r
261   list-style-type: upper-roman;\r
262 }\r
263 \r
264 div.compact ul, div.compact ol,\r
265 div.compact p, div.compact p,\r
266 div.compact div, div.compact div {\r
267   margin-top: 0.1em;\r
268   margin-bottom: 0.1em;\r
269 }\r
270 \r
271 tfoot {\r
272   font-weight: bold;\r
273 }\r
274 td > div.verse {\r
275   white-space: pre;\r
276 }\r
277 \r
278 div.hdlist {\r
279   margin-top: 0.8em;\r
280   margin-bottom: 0.8em;\r
281 }\r
282 div.hdlist tr {\r
283   padding-bottom: 15px;\r
284 }\r
285 dt.hdlist1.strong, td.hdlist1.strong {\r
286   font-weight: bold;\r
287 }\r
288 td.hdlist1 {\r
289   vertical-align: top;\r
290   font-style: normal;\r
291   padding-right: 0.8em;\r
292   color: navy;\r
293 }\r
294 td.hdlist2 {\r
295   vertical-align: top;\r
296 }\r
297 div.hdlist.compact tr {\r
298   margin: 0;\r
299   padding-bottom: 0;\r
300 }\r
301 \r
302 .comment {\r
303   background: yellow;\r
304 }\r
305 \r
306 .footnote, .footnoteref {\r
307   font-size: 0.8em;\r
308 }\r
309 \r
310 span.footnote, span.footnoteref {\r
311   vertical-align: super;\r
312 }\r
313 \r
314 #footnotes {\r
315   margin: 20px 0 20px 0;\r
316   padding: 7px 0 0 0;\r
317 }\r
318 \r
319 #footnotes div.footnote {\r
320   margin: 0 0 5px 0;\r
321 }\r
322 \r
323 #footnotes hr {\r
324   border: none;\r
325   border-top: 1px solid silver;\r
326   height: 1px;\r
327   text-align: left;\r
328   margin-left: 0;\r
329   width: 20%;\r
330   min-width: 100px;\r
331 }\r
332 \r
333 div.colist td {\r
334   padding-right: 0.5em;\r
335   padding-bottom: 0.3em;\r
336   vertical-align: top;\r
337 }\r
338 div.colist td img {\r
339   margin-top: 0.3em;\r
340 }\r
341 \r
342 @media print {\r
343   #footer-badges { display: none; }\r
344 }\r
345 \r
346 #toc {\r
347   margin-bottom: 2.5em;\r
348 }\r
349 \r
350 #toctitle {\r
351   color: #527bbd;\r
352   font-size: 1.1em;\r
353   font-weight: bold;\r
354   margin-top: 1.0em;\r
355   margin-bottom: 0.1em;\r
356 }\r
357 \r
358 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {\r
359   margin-top: 0;\r
360   margin-bottom: 0;\r
361 }\r
362 div.toclevel2 {\r
363   margin-left: 2em;\r
364   font-size: 0.9em;\r
365 }\r
366 div.toclevel3 {\r
367   margin-left: 4em;\r
368   font-size: 0.9em;\r
369 }\r
370 div.toclevel4 {\r
371   margin-left: 6em;\r
372   font-size: 0.9em;\r
373 }\r
374 \r
375 span.aqua { color: aqua; }\r
376 span.black { color: black; }\r
377 span.blue { color: blue; }\r
378 span.fuchsia { color: fuchsia; }\r
379 span.gray { color: gray; }\r
380 span.green { color: green; }\r
381 span.lime { color: lime; }\r
382 span.maroon { color: maroon; }\r
383 span.navy { color: navy; }\r
384 span.olive { color: olive; }\r
385 span.purple { color: purple; }\r
386 span.red { color: red; }\r
387 span.silver { color: silver; }\r
388 span.teal { color: teal; }\r
389 span.white { color: white; }\r
390 span.yellow { color: yellow; }\r
391 \r
392 span.aqua-background { background: aqua; }\r
393 span.black-background { background: black; }\r
394 span.blue-background { background: blue; }\r
395 span.fuchsia-background { background: fuchsia; }\r
396 span.gray-background { background: gray; }\r
397 span.green-background { background: green; }\r
398 span.lime-background { background: lime; }\r
399 span.maroon-background { background: maroon; }\r
400 span.navy-background { background: navy; }\r
401 span.olive-background { background: olive; }\r
402 span.purple-background { background: purple; }\r
403 span.red-background { background: red; }\r
404 span.silver-background { background: silver; }\r
405 span.teal-background { background: teal; }\r
406 span.white-background { background: white; }\r
407 span.yellow-background { background: yellow; }\r
408 \r
409 span.big { font-size: 2em; }\r
410 span.small { font-size: 0.6em; }\r
411 \r
412 span.underline { text-decoration: underline; }\r
413 span.overline { text-decoration: overline; }\r
414 span.line-through { text-decoration: line-through; }\r
415 \r
416 div.unbreakable { page-break-inside: avoid; }\r
417 \r
418 \r
419 /*\r
420  * xhtml11 specific\r
421  *\r
422  * */\r
423 \r
424 div.tableblock {\r
425   margin-top: 1.0em;\r
426   margin-bottom: 1.5em;\r
427 }\r
428 div.tableblock > table {\r
429   border: 3px solid #527bbd;\r
430 }\r
431 thead, p.table.header {\r
432   font-weight: bold;\r
433   color: #527bbd;\r
434 }\r
435 p.table {\r
436   margin-top: 0;\r
437 }\r
438 /* Because the table frame attribute is overriden by CSS in most browsers. */\r
439 div.tableblock > table[frame="void"] {\r
440   border-style: none;\r
441 }\r
442 div.tableblock > table[frame="hsides"] {\r
443   border-left-style: none;\r
444   border-right-style: none;\r
445 }\r
446 div.tableblock > table[frame="vsides"] {\r
447   border-top-style: none;\r
448   border-bottom-style: none;\r
449 }\r
450 \r
451 \r
452 /*\r
453  * html5 specific\r
454  *\r
455  * */\r
456 \r
457 table.tableblock {\r
458   margin-top: 1.0em;\r
459   margin-bottom: 1.5em;\r
460 }\r
461 thead, p.tableblock.header {\r
462   font-weight: bold;\r
463   color: #527bbd;\r
464 }\r
465 p.tableblock {\r
466   margin-top: 0;\r
467 }\r
468 table.tableblock {\r
469   border-width: 3px;\r
470   border-spacing: 0px;\r
471   border-style: solid;\r
472   border-color: #527bbd;\r
473   border-collapse: collapse;\r
474 }\r
475 th.tableblock, td.tableblock {\r
476   border-width: 1px;\r
477   padding: 4px;\r
478   border-style: solid;\r
479   border-color: #527bbd;\r
480 }\r
481 \r
482 table.tableblock.frame-topbot {\r
483   border-left-style: hidden;\r
484   border-right-style: hidden;\r
485 }\r
486 table.tableblock.frame-sides {\r
487   border-top-style: hidden;\r
488   border-bottom-style: hidden;\r
489 }\r
490 table.tableblock.frame-none {\r
491   border-style: hidden;\r
492 }\r
493 \r
494 th.tableblock.halign-left, td.tableblock.halign-left {\r
495   text-align: left;\r
496 }\r
497 th.tableblock.halign-center, td.tableblock.halign-center {\r
498   text-align: center;\r
499 }\r
500 th.tableblock.halign-right, td.tableblock.halign-right {\r
501   text-align: right;\r
502 }\r
503 \r
504 th.tableblock.valign-top, td.tableblock.valign-top {\r
505   vertical-align: top;\r
506 }\r
507 th.tableblock.valign-middle, td.tableblock.valign-middle {\r
508   vertical-align: middle;\r
509 }\r
510 th.tableblock.valign-bottom, td.tableblock.valign-bottom {\r
511   vertical-align: bottom;\r
512 }\r
513 \r
514 \r
515 /*\r
516  * manpage specific\r
517  *\r
518  * */\r
519 \r
520 body.manpage h1 {\r
521   padding-top: 0.5em;\r
522   padding-bottom: 0.5em;\r
523   border-top: 2px solid silver;\r
524   border-bottom: 2px solid silver;\r
525 }\r
526 body.manpage h2 {\r
527   border-style: none;\r
528 }\r
529 body.manpage div.sectionbody {\r
530   margin-left: 3em;\r
531 }\r
532 \r
533 @media print {\r
534   body.manpage div#toc { display: none; }\r
535 }\r
536 \r
537 \r
538 </style>\r
539 <script type="text/javascript">\r
540 /*<![CDATA[*/\r
541 var asciidoc = {  // Namespace.\r
542 \r
543 /////////////////////////////////////////////////////////////////////\r
544 // Table Of Contents generator\r
545 /////////////////////////////////////////////////////////////////////\r
546 \r
547 /* Author: Mihai Bazon, September 2002\r
548  * http://students.infoiasi.ro/~mishoo\r
549  *\r
550  * Table Of Content generator\r
551  * Version: 0.4\r
552  *\r
553  * Feel free to use this script under the terms of the GNU General Public\r
554  * License, as long as you do not remove or alter this notice.\r
555  */\r
556 \r
557  /* modified by Troy D. Hanson, September 2006. License: GPL */\r
558  /* modified by Stuart Rackham, 2006, 2009. License: GPL */\r
559 \r
560 // toclevels = 1..4.\r
561 toc: function (toclevels) {\r
562 \r
563   function getText(el) {\r
564     var text = "";\r
565     for (var i = el.firstChild; i != null; i = i.nextSibling) {\r
566       if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.\r
567         text += i.data;\r
568       else if (i.firstChild != null)\r
569         text += getText(i);\r
570     }\r
571     return text;\r
572   }\r
573 \r
574   function TocEntry(el, text, toclevel) {\r
575     this.element = el;\r
576     this.text = text;\r
577     this.toclevel = toclevel;\r
578   }\r
579 \r
580   function tocEntries(el, toclevels) {\r
581     var result = new Array;\r
582     var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');\r
583     // Function that scans the DOM tree for header elements (the DOM2\r
584     // nodeIterator API would be a better technique but not supported by all\r
585     // browsers).\r
586     var iterate = function (el) {\r
587       for (var i = el.firstChild; i != null; i = i.nextSibling) {\r
588         if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {\r
589           var mo = re.exec(i.tagName);\r
590           if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {\r
591             result[result.length] = new TocEntry(i, getText(i), mo[1]-1);\r
592           }\r
593           iterate(i);\r
594         }\r
595       }\r
596     }\r
597     iterate(el);\r
598     return result;\r
599   }\r
600 \r
601   var toc = document.getElementById("toc");\r
602   if (!toc) {\r
603     return;\r
604   }\r
605 \r
606   // Delete existing TOC entries in case we're reloading the TOC.\r
607   var tocEntriesToRemove = [];\r
608   var i;\r
609   for (i = 0; i < toc.childNodes.length; i++) {\r
610     var entry = toc.childNodes[i];\r
611     if (entry.nodeName.toLowerCase() == 'div'\r
612      && entry.getAttribute("class")\r
613      && entry.getAttribute("class").match(/^toclevel/))\r
614       tocEntriesToRemove.push(entry);\r
615   }\r
616   for (i = 0; i < tocEntriesToRemove.length; i++) {\r
617     toc.removeChild(tocEntriesToRemove[i]);\r
618   }\r
619 \r
620   // Rebuild TOC entries.\r
621   var entries = tocEntries(document.getElementById("content"), toclevels);\r
622   for (var i = 0; i < entries.length; ++i) {\r
623     var entry = entries[i];\r
624     if (entry.element.id == "")\r
625       entry.element.id = "_toc_" + i;\r
626     var a = document.createElement("a");\r
627     a.href = "#" + entry.element.id;\r
628     a.appendChild(document.createTextNode(entry.text));\r
629     var div = document.createElement("div");\r
630     div.appendChild(a);\r
631     div.className = "toclevel" + entry.toclevel;\r
632     toc.appendChild(div);\r
633   }\r
634   if (entries.length == 0)\r
635     toc.parentNode.removeChild(toc);\r
636 },\r
637 \r
638 \r
639 /////////////////////////////////////////////////////////////////////\r
640 // Footnotes generator\r
641 /////////////////////////////////////////////////////////////////////\r
642 \r
643 /* Based on footnote generation code from:\r
644  * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html\r
645  */\r
646 \r
647 footnotes: function () {\r
648   // Delete existing footnote entries in case we're reloading the footnodes.\r
649   var i;\r
650   var noteholder = document.getElementById("footnotes");\r
651   if (!noteholder) {\r
652     return;\r
653   }\r
654   var entriesToRemove = [];\r
655   for (i = 0; i < noteholder.childNodes.length; i++) {\r
656     var entry = noteholder.childNodes[i];\r
657     if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")\r
658       entriesToRemove.push(entry);\r
659   }\r
660   for (i = 0; i < entriesToRemove.length; i++) {\r
661     noteholder.removeChild(entriesToRemove[i]);\r
662   }\r
663 \r
664   // Rebuild footnote entries.\r
665   var cont = document.getElementById("content");\r
666   var spans = cont.getElementsByTagName("span");\r
667   var refs = {};\r
668   var n = 0;\r
669   for (i=0; i<spans.length; i++) {\r
670     if (spans[i].className == "footnote") {\r
671       n++;\r
672       var note = spans[i].getAttribute("data-note");\r
673       if (!note) {\r
674         // Use [\s\S] in place of . so multi-line matches work.\r
675         // Because JavaScript has no s (dotall) regex flag.\r
676         note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];\r
677         spans[i].innerHTML =\r
678           "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +\r
679           "' title='View footnote' class='footnote'>" + n + "</a>]";\r
680         spans[i].setAttribute("data-note", note);\r
681       }\r
682       noteholder.innerHTML +=\r
683         "<div class='footnote' id='_footnote_" + n + "'>" +\r
684         "<a href='#_footnoteref_" + n + "' title='Return to text'>" +\r
685         n + "</a>. " + note + "</div>";\r
686       var id =spans[i].getAttribute("id");\r
687       if (id != null) refs["#"+id] = n;\r
688     }\r
689   }\r
690   if (n == 0)\r
691     noteholder.parentNode.removeChild(noteholder);\r
692   else {\r
693     // Process footnoterefs.\r
694     for (i=0; i<spans.length; i++) {\r
695       if (spans[i].className == "footnoteref") {\r
696         var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");\r
697         href = href.match(/#.*/)[0];  // Because IE return full URL.\r
698         n = refs[href];\r
699         spans[i].innerHTML =\r
700           "[<a href='#_footnote_" + n +\r
701           "' title='View footnote' class='footnote'>" + n + "</a>]";\r
702       }\r
703     }\r
704   }\r
705 },\r
706 \r
707 install: function(toclevels) {\r
708   var timerId;\r
709 \r
710   function reinstall() {\r
711     asciidoc.footnotes();\r
712     if (toclevels) {\r
713       asciidoc.toc(toclevels);\r
714     }\r
715   }\r
716 \r
717   function reinstallAndRemoveTimer() {\r
718     clearInterval(timerId);\r
719     reinstall();\r
720   }\r
721 \r
722   timerId = setInterval(reinstall, 500);\r
723   if (document.addEventListener)\r
724     document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);\r
725   else\r
726     window.onload = reinstallAndRemoveTimer;\r
727 }\r
728 \r
729 }\r
730 asciidoc.install();\r
731 /*]]>*/\r
732 </script>\r
733 </head>\r
734 <body class="article">\r
735 <div id="header">\r
736 <h1>ZSH-LOVERS(1)</h1>\r
737 </div>\r
738 <div id="content">\r
739 <div class="sect1">\r
740 <h2 id="_name">NAME</h2>\r
741 <div class="sectionbody">\r
742 <div class="paragraph"><p>zsh-lovers - tips, tricks and examples for the Z shell</p></div>\r
743 </div>\r
744 </div>\r
745 <div class="sect1">\r
746 <h2 id="_synopsis">SYNOPSIS</h2>\r
747 <div class="sectionbody">\r
748 <div class="paragraph"><p>Just read it. ;-)</p></div>\r
749 </div>\r
750 </div>\r
751 <div class="sect1">\r
752 <h2 id="_overview">OVERVIEW</h2>\r
753 <div class="sectionbody">\r
754 <div class="paragraph"><p>Whenever we look at the zsh manual we wonder why there are no examples or those\r
755 simply things in (shell) life.  The zsh contains many features, but there was no\r
756 manpage with some examples (like procmailex(5)).  That&#8217;s why we wrote this\r
757 manpage.</p></div>\r
758 <div class="paragraph"><p>Most of the tricks and oneliner come from the mailinglists zsh-users,\r
759 zsh-workers, google, newsgroups and from ourself.  See section <strong>LINKS</strong> for\r
760 details.</p></div>\r
761 <div class="paragraph"><p>Note: This manpage (zsh-lovers(1)) is <strong>not</strong> an offical part of the Z shell! It&#8217;s\r
762 just a just for fun - manpage ;)<br />\r
763 For comments, bugreports and feedback take a quick look at the section <strong>BUGS</strong>.</p></div>\r
764 </div>\r
765 </div>\r
766 <div class="sect1">\r
767 <h2 id="_shell_scripting">SHELL-SCRIPTING</h2>\r
768 <div class="sectionbody">\r
769 <div class="paragraph"><p>This section provides some examples for often needed shellscript-stuff. Notice\r
770 that you should not use otherwise most examples won&#8217;t work.<br />\r
771 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski\r
772 (<a href="http://www.chodorowski.com/projects/zws/">http://www.chodorowski.com/projects/zws/</a>):</p></div>\r
773 <div class="listingblock">\r
774 <div class="content">\r
775 <pre><code>parse_options()\r
776 {\r
777     o_port=(-p 9999)\r
778     o_root=(-r WWW)\r
779     o_log=(-d ZWS.log)\r
780 \r
781     zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help\r
782     if [[ $? != 0 || "$o_help" != "" ]]; then\r
783         echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"\r
784         exit 1\r
785     fi\r
786 \r
787     port=$o_port[2]\r
788     root=$o_root[2]\r
789     log=$o_log[2]\r
790 \r
791     if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi\r
792 }\r
793 # now use the function:\r
794 parse_options $*</code></pre>\r
795 </div></div>\r
796 </div>\r
797 </div>\r
798 <div class="sect1">\r
799 <h2 id="_examples">EXAMPLES</h2>\r
800 <div class="sectionbody">\r
801 <div class="paragraph"><p>Available subsections are <strong>Aliases</strong>, <strong>Completion</strong>, <strong>Unsorted/Misc examples</strong>,\r
802 <strong>(Recursive) Globbing - Examples</strong>, <strong>Modifiers usage</strong>, <strong>Redirection-Examples</strong>,\r
803 <strong>ZMV-Examples</strong> and <strong>Module-Examples</strong>.</p></div>\r
804 <div class="sect2">\r
805 <h3 id="_aliases">ALIASES</h3>\r
806 <div class="paragraph"><p>Suffix aliases are supported in zsh since version 4.2.0. Some examples:</p></div>\r
807 <div class="listingblock">\r
808 <div class="content">\r
809 <pre><code>alias -s tex=vim\r
810 alias -s html=w3m\r
811 alias -s org=w3m</code></pre>\r
812 </div></div>\r
813 <div class="paragraph"><p>Now pressing return-key after entering <em>foobar.tex</em> starts vim with\r
814 foobar.tex. Calling a html-file runs browser w3m. <em>www.zsh.org</em> and pressing\r
815 enter starts w3m with argument www.zsh.org.<br />\r
816 Global aliases can be used anywhere in the command line. Example:</p></div>\r
817 <div class="listingblock">\r
818 <div class="content">\r
819 <pre><code>$ alias -g C='| wc -l'\r
820 $ grep alias ~/.zsh/* C\r
821 443</code></pre>\r
822 </div></div>\r
823 <div class="paragraph"><p>Some more or less useful global aliases (choose whether they are useful  or not\r
824 for you on your own):</p></div>\r
825 <div class="listingblock">\r
826 <div class="content">\r
827 <pre><code>alias -g ...='../..'\r
828 alias -g ....='../../..'\r
829 alias -g .....='../../../..'\r
830 alias -g CA="2&gt;&amp;1 | cat -A"\r
831 alias -g C='| wc -l'\r
832 alias -g D="DISPLAY=:0.0"\r
833 alias -g DN=/dev/null\r
834 alias -g ED="export DISPLAY=:0.0"\r
835 alias -g EG='|&amp; egrep'\r
836 alias -g EH='|&amp; head'\r
837 alias -g EL='|&amp; less'\r
838 alias -g ELS='|&amp; less -S'\r
839 alias -g ETL='|&amp; tail -20'\r
840 alias -g ET='|&amp; tail'\r
841 alias -g F=' | fmt -'\r
842 alias -g G='| egrep'\r
843 alias -g H='| head'\r
844 alias -g HL='|&amp; head -20'\r
845 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"\r
846 alias -g LL="2&gt;&amp;1 | less"\r
847 alias -g L="| less"\r
848 alias -g LS='| less -S'\r
849 alias -g MM='| most'\r
850 alias -g M='| more'\r
851 alias -g NE="2&gt; /dev/null"\r
852 alias -g NS='| sort -n'\r
853 alias -g NUL="&gt; /dev/null 2&gt;&amp;1"\r
854 alias -g PIPE='|'\r
855 alias -g R=' &gt; /c/aaa/tee.txt '\r
856 alias -g RNS='| sort -nr'\r
857 alias -g S='| sort'\r
858 alias -g TL='| tail -20'\r
859 alias -g T='| tail'\r
860 alias -g US='| sort -u'\r
861 alias -g VM=/var/log/messages\r
862 alias -g X0G='| xargs -0 egrep'\r
863 alias -g X0='| xargs -0'\r
864 alias -g XG='| xargs egrep'\r
865 alias -g X='| xargs'</code></pre>\r
866 </div></div>\r
867 </div>\r
868 <div class="sect2">\r
869 <h3 id="_completion">COMPLETION</h3>\r
870 <div class="paragraph"><p>See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old\r
871 style of zsh programmable completion, zshcompsys is the new completion\r
872 system, zshcompwid are the zsh completion widgets.</p></div>\r
873 <div class="paragraph"><p>Some functions, like _apt and _dpkg, are very slow. You can use a cache\r
874 in order to proxy the list of  results  (like  the  list  of  available\r
875 debian packages) Use a cache:</p></div>\r
876 <div class="listingblock">\r
877 <div class="content">\r
878 <pre><code>zstyle ':completion:*' use-cache on\r
879 zstyle ':completion:*' cache-path ~/.zsh/cache</code></pre>\r
880 </div></div>\r
881 <div class="paragraph"><p>Prevent CVS files/directories from being completed:</p></div>\r
882 <div class="listingblock">\r
883 <div class="content">\r
884 <pre><code>zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'\r
885 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'</code></pre>\r
886 </div></div>\r
887 <div class="paragraph"><p>Fuzzy matching of completions for when you mistype them:</p></div>\r
888 <div class="listingblock">\r
889 <div class="content">\r
890 <pre><code>zstyle ':completion:*' completer _complete _match _approximate\r
891 zstyle ':completion:*:match:*' original only\r
892 zstyle ':completion:*:approximate:*' max-errors 1 numeric</code></pre>\r
893 </div></div>\r
894 <div class="paragraph"><p>And  if  you  want  the  number  of  errors  allowed by _approximate to\r
895 increase with the length of what you have typed so far:</p></div>\r
896 <div class="listingblock">\r
897 <div class="content">\r
898 <pre><code>zstyle -e ':completion:*:approximate:*' \\r
899         max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'</code></pre>\r
900 </div></div>\r
901 <div class="paragraph"><p>Ignore completion functions for commands you don&#8217;t have:</p></div>\r
902 <div class="listingblock">\r
903 <div class="content">\r
904 <pre><code>zstyle ':completion:*:functions' ignored-patterns '_*'</code></pre>\r
905 </div></div>\r
906 <div class="paragraph"><p>With helper functions like:</p></div>\r
907 <div class="listingblock">\r
908 <div class="content">\r
909 <pre><code>xdvi() { command xdvi ${*:-*.dvi(om[1])} }</code></pre>\r
910 </div></div>\r
911 <div class="paragraph"><p>you can avoid having to complete at all in many cases, but if  you  do,\r
912 you  might want to fall into menu selection immediately and to have the\r
913 words sorted by time:</p></div>\r
914 <div class="listingblock">\r
915 <div class="content">\r
916 <pre><code>zstyle ':completion:*:*:xdvi:*' menu yes select\r
917 zstyle ':completion:*:*:xdvi:*' file-sort time</code></pre>\r
918 </div></div>\r
919 <div class="paragraph"><p>Completing process IDs with menu selection:</p></div>\r
920 <div class="listingblock">\r
921 <div class="content">\r
922 <pre><code>zstyle ':completion:*:*:kill:*' menu yes select\r
923 zstyle ':completion:*:kill:*'   force-list always</code></pre>\r
924 </div></div>\r
925 <div class="paragraph"><p>If you end up using a directory  as  argument,  this  will  remove  the\r
926 trailing slash (usefull in ln)</p></div>\r
927 <div class="listingblock">\r
928 <div class="content">\r
929 <pre><code>zstyle ':completion:*' squeeze-slashes true</code></pre>\r
930 </div></div>\r
931 <div class="paragraph"><p>cd will never select the parent directory (e.g.: cd ../&lt;TAB&gt;):</p></div>\r
932 <div class="listingblock">\r
933 <div class="content">\r
934 <pre><code>zstyle ':completion:*:cd:*' ignore-parents parent pwd</code></pre>\r
935 </div></div>\r
936 <div class="paragraph"><p>Another method for <em>quick change directories</em>. Add this to your ~/.zshrc, then just enter\r
937 &#8220;cd &#8230;./dir&#8221;</p></div>\r
938 <div class="listingblock">\r
939 <div class="content">\r
940 <pre><code>rationalise-dot() {\r
941   if [[ $LBUFFER = *.. ]]; then\r
942     LBUFFER+=/..\r
943   else\r
944     LBUFFER+=.\r
945   fi\r
946 }\r
947 zle -N rationalise-dot\r
948 bindkey . rationalise-dot</code></pre>\r
949 </div></div>\r
950 </div>\r
951 <div class="sect2">\r
952 <h3 id="_unsorted_misc_examples">UNSORTED/MISC examples</h3>\r
953 <div class="paragraph"><p>Hint: A list of valid glob Qualifiers can be found in zshexpn(1).\r
954 See &#8220;man 1 zshexpn | less -p&#8221; Qualifiers for details.</p></div>\r
955 <div class="listingblock">\r
956 <div class="content">\r
957 <pre><code># Get the names of all files that *don't* match a pattern *anywhere* on the\r
958 # file (and without ``-L'' because its GNUish)\r
959   $ print -rl -- *(.^e{'grep -q pattern $REPLY'})\r
960   # or\r
961   $ : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'})\r
962 \r
963 # random numbers\r
964   $ echo $[${RANDOM}%1000]     # random between 0-999\r
965   $ echo $[${RANDOM}%11+10]    # random between 10-20\r
966   $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)\r
967 \r
968 # reverse a word\r
969   $ echo "${(j::)${(@Oa)${(s::):-hello}}}"\r
970 \r
971 # Show newest directory\r
972   $ ls -ld *(/om[1])\r
973 \r
974 # random array element\r
975   $ FILES=( .../files/* )\r
976   $ feh $FILES[$RANDOM%$#FILES+1]\r
977 \r
978 # cat first line in all files in this dir\r
979   $ for file (*(ND-.)) IFS= read -re &lt; $file\r
980 \r
981 # test if a parameter is numeric\r
982   $ if [[ $1 == &lt;-&gt; ]] ; then\r
983          echo numeric\r
984     else\r
985          echo non-numeric\r
986     fi\r
987 \r
988 # Show me all the .c files for which there doesn't exist a .o file.\r
989   $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)\r
990 \r
991 # All files in /var/ that are not owned by root\r
992   $ ls -ld /var/*(^u:root)\r
993 \r
994 # All files for which the owner hat read and execute permissions\r
995   $ echo *(f:u+rx:)\r
996 \r
997 # The same, but also others dont have execute permissions\r
998   $ echo *(f:u+rx,o-x:)\r
999 \r
1000 # brace expansion - example\r
1001   $ X=(A B C)\r
1002   $ Y=(+ -)\r
1003   $ print -r -- $^X.$^Y\r
1004   A.+ A.- B.+ B.- C.+ C.-\r
1005 \r
1006 # Fetch the newest file containing the string 'fgractg*.log' in the\r
1007 # filename and contains the string 'ORA-' in it\r
1008   $ file=(fgractg*.log(Nm0om[1]))\r
1009   $ (($#file)) &amp;&amp; grep -l ORA- $file\r
1010   # without Zsh\r
1011   $ files=$( find . -name . -o -prune -name 'fgractg*&gt;log' -mtime 0 -print )\r
1012   &gt; if [ -n "$files" ]; then\r
1013   &gt;    IFS='\r
1014   &gt; '\r
1015   &gt; set -f\r
1016   &gt; file=$(ls -td $files | head -1)\r
1017   &gt; grep -l ORA- "$file"\r
1018   &gt; fi\r
1019 \r
1020 # keep specified number of child processes running until entire task finished\r
1021   $ zsh -c 'sleep 1 &amp; sleep 3 &amp; sleep 2&amp; print -rl -- $jobtexts'\r
1022 \r
1023 # Remove zero length and .bak files in a directory\r
1024   $ rm -i *(.L0) *.bak(.)\r
1025 \r
1026 # print out files that dont have extensions\r
1027   $ printf '%s\n' ^?*.*\r
1028   $ printf '%s\n' ^?*.[^.]*(D)\r
1029   $ ls -d -- ^?*.*(D)\r
1030 \r
1031 # Finding files which does not contain a specific string\r
1032   $ print -rl file* | comm -2 -3 - &lt;(grep -l string file*)'\r
1033   $ for f (file*(N)) grep -q string $f || print -r $f'\r
1034 \r
1035 # Show/Check whether a option is set or not. It works both with $options as\r
1036 # with $builtins\r
1037   $ echo $options[correct]\r
1038   off\r
1039   $ $options[zle]\r
1040   on\r
1041 \r
1042 # Count the number of directories on the stack\r
1043   $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or\r
1044   $ dirs -v | awk '{n=$1}END{print n+1}'\r
1045 \r
1046 # Matching all files which do not have a dot in filename\r
1047   $ ls *~*.*(.)\r
1048 \r
1049 # Show only the ip-address from ``ifconfig device''\r
1050   # ifconfig from net-tools (Linux)\r
1051   $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}\r
1052   # ifconfig from 4.2BSD {Free,Net,Open}BSD\r
1053   $ print ${$(/sbin/ifconfig tun0)[6]}\r
1054 \r
1055 # Ping all the IP addresses in a couple of class C's or all hosts\r
1056 # into /etc/hosts\r
1057   $ for i in {1..254}; do ping -c 1 192.168.13.$i; done\r
1058   or\r
1059   $ I=1\r
1060   $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done\r
1061   or\r
1062   $ for i in $(sed 's/#.*//' &gt; /etc/hosts | awk '{print $2}')\r
1063   : do\r
1064   :    echo "Trying $i ... "\r
1065   :    ping -c 1 $i ;\r
1066   :    echo '============================='\r
1067   : done\r
1068 \r
1069 # load all available modules at startup\r
1070   $ typeset -U m\r
1071   $ m=()\r
1072   $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))\r
1073   $ zmodload -i $m\r
1074 \r
1075 # Rename all files within a directory such that their names get a numeral\r
1076 # prefix in the default sort order.\r
1077   $ i=1; for j in *; do mv $j $i.$j; ((i++)); done\r
1078   $ i=1; for f in *; do mv $f $(echo $i | \\r
1079     awk '{ printf("%03d", $0)}').$f; ((i++)); done\r
1080   $ integer i=0; for f in *; do mv $f $[i+=1].$f; done\r
1081 \r
1082 # Find (and print) all symbolic links without a target within the current\r
1083 # dirtree.\r
1084   $ $ file **/*(D@) | fgrep broken\r
1085   $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i\r
1086   $ echo **/*(@-^./=%p)\r
1087   $ print -l **/*(-@)\r
1088 \r
1089 # List all plain files that do not have extensions listed in `fignore'\r
1090   $ ls **/*~*(${~${(j/|/)fignore}})(.)\r
1091   # see above, but now omit executables\r
1092   $ ls **/*~*(${~${(j/|/)fignore}})(.^*)\r
1093 \r
1094 # Print out files that dont have extensions (require *setopt extendedglob*\r
1095 # and *setopt dotglob*)\r
1096   $ printf '%s\n' ^?*.*\r
1097 \r
1098 # List files in reverse order sorted by name\r
1099   $ print -rl -- *(On)\r
1100   or\r
1101   $ print -rl -- *(^on)\r
1102 \r
1103 # Synonymic to ``ps ax | awk '{print $1}'''\r
1104   $ print -l /proc/*/cwd(:h:t:s/self//)\r
1105 \r
1106 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..\r
1107 # (under Linux)\r
1108   $ pid2 () {\r
1109   &gt;   local i\r
1110   &gt;   for i in /proc/&lt;-&gt;/stat\r
1111   &gt; do\r
1112   &gt;   [[ "$(&lt; $i)" = *\((${(j:|:)~@})\)* ]] &amp;&amp; echo $i:h:t\r
1113   &gt; done\r
1114   &gt; }\r
1115 \r
1116 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...\r
1117   $ for (( i = 36#n; i &lt;= 36#y; i++ )); do\r
1118   &gt;   print ${$(([##36]i)):l}\r
1119   &gt; done\r
1120 # or in combination with ``dc''\r
1121   $ print {$((##n))..$((##y))}P\ 10P | dc\r
1122 # or with ``eval''\r
1123   $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'\r
1124 \r
1125 # foreach in one line of shell\r
1126   $ for f (*) print -r -- $f\r
1127 \r
1128 # copy a directory recursively without data/files\r
1129   $ dirs=(**/*(/))\r
1130   $ cd -- $dest_root\r
1131   $ mkdir -p -- $dirs\r
1132 # or without zsh\r
1133   $ find . -type d -exec env d="$dest_root" \\r
1134     sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;\r
1135 \r
1136 # If `foo=23'', then print with 10 digit with leading '0'.\r
1137   $ foo=23\r
1138   $ print ${(r:10::0:)foo}\r
1139 \r
1140 # find the name of all the files in their home directory that have\r
1141 # more than 20 characters in their file names\r
1142   print -rl $HOME/${(l:20::?:)~:-}*\r
1143 \r
1144 # Save arrays\r
1145   $ print -r -- ${(qq)m} &gt; $nameoffile      # save it\r
1146   $ eval "m=($(cat -- $nameoffile)"            # or use\r
1147   $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it\r
1148 \r
1149 # get a "ls -l" on all the files in the tree that are younger than a\r
1150 # specified age (e.g "ls -l" all the files in the tree that where\r
1151 # modified in the last 2 days)\r
1152   $ ls -tld **/*(m-2)\r
1153 # This will give you a listing 1 file perl line (not Ã  la ls -R).\r
1154 # Think of an easy way to have a "ls -R" style output with\r
1155 # only files newer than 2 day old.\r
1156   $ for d (. ./**/*(/)) {\r
1157   &gt;   print -r -- $'\n'${d}:\r
1158   &gt;   cd $d &amp;&amp; {\r
1159   &gt;       l=(*(Nm-2))\r
1160   &gt;       (($#l)) &amp;&amp; ls -ltd -- $l\r
1161   &gt;       cd ~-\r
1162   &gt;   }\r
1163   &gt; }\r
1164 # If you also want directories to be included even if their mtime\r
1165 # is more than 2 days old:\r
1166   $ for d (. ./**/*(/)) {\r
1167   &gt;   print -r -- $'\n'${d}:\r
1168   &gt;   cd $d &amp;&amp; {\r
1169   &gt;      l=(*(N/,m-2))\r
1170   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l\r
1171   &gt;      cd ~-\r
1172   &gt;   }\r
1173   &gt; }\r
1174 # And if you want only the directories with mtime &lt; 2 days to be listed:\r
1175   $ for d (. ./**/*(N/m-2)) {\r
1176   &gt;   print -r -- $'\n'${d}:\r
1177   &gt;   cd $d &amp;&amp; {\r
1178   &gt;      l=(*(Nm-2))\r
1179   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l\r
1180   &gt;      cd ~-\r
1181   &gt;   }\r
1182   &gt; }\r
1183 \r
1184 # print 42 ``-''\r
1185   $ echo ${(l:42::-:)}\r
1186 # or use ``$COLUMS''\r
1187   $ echo ${(l:$COLUMNS::-:)}\r
1188 # and now with colors (require autoload colors ;colors)\r
1189   $ echo "$bg[red]$fg[black]${(l:42::-:)}"\r
1190 \r
1191 # Redirect STDERR to a command like xless without redirecting STDOUT as well.\r
1192   $ foo 2&gt;&gt;(xless)\r
1193 # but this executes the command asynchronously. To do it synchronously:\r
1194   $ { { foo 1&gt;&amp;3 } 2&gt;&amp;1 | xless } 3&gt;&amp;1\r
1195 \r
1196 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3\r
1197   $ for i in *.mp3; do\r
1198   &gt;     mv $i ${${(C)i}:s/Mp3/mp3/}\r
1199   &gt; done\r
1200 \r
1201 # Match file names containing only digits and ending with .xml (require\r
1202 # *setopt kshglob*)\r
1203   $ ls -l [0-9]##.xml\r
1204   $ ls -l &lt;0-&gt;.xml\r
1205 \r
1206 # Remove all "non txt" files\r
1207   $ rm ./^*.txt\r
1208 \r
1209 # Move 200 files from a directory into another\r
1210   $ mv -- *([1,200]) /another/Dir\r
1211 \r
1212 # Convert images (foo.gif =&gt; foo.png):\r
1213   $ for i in **/*.gif; convert $i $i:r.png\r
1214 \r
1215 # convert a collection of mp3 files to wave or cdr,\r
1216 # e.g. file.wav -&gt; file.mp3)\r
1217   $ for i (./*.mp3){mpg321 --w - $i &gt; ${i:r}.wav}\r
1218 \r
1219 # Download with LaTeX2HTML  created Files (for example the ZSH-Guide):\r
1220   $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do\r
1221   &gt;     lynx -source $f &gt;${f:t}\r
1222   &gt; done\r
1223 \r
1224 # Move all files in dir1 and dir2 that have line counts greater than 10 to\r
1225 # another directory say "/more10"\r
1226   $ mv dir[12]/**/*.cr(-.e{'((`wc -l &lt; $REPLY` &gt; 10))'}) /more10\r
1227 \r
1228 # Make with dpkg a master-list of everyfile that it has installed\r
1229   $ diff &lt;(find / | sort) &lt;(cat /var/lib/dpkg/info/*.list | sort)\r
1230 \r
1231 # Replace this fucking Escape-Sequences:\r
1232   $ autoload colors ; colors\r
1233   $ print "$bg[cyan]$fg[blue]You are a idiot" &gt;&gt; /dev/pts/3\r
1234 \r
1235 # Get ASCII value of a character\r
1236   $ char=N ; print $((#char))\r
1237 \r
1238 # Filename "Erweiterung"\r
1239 # Note: The (N) says to use the nullglob option for this particular\r
1240 # glob pattern.\r
1241   $ for i in *.o(N); do\r
1242   &gt;     rm $i\r
1243   &gt; done\r
1244 \r
1245 # Rename files; i. e. FOO to foo and bar to BAR\r
1246   $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'\r
1247   $ for i in *(.); mv $i ${i:u} # `bar to `BAR'\r
1248 \r
1249 # Show all suid-files in $PATH\r
1250   $ ls -latg ${(s.:.)PATH} | grep '^...s'\r
1251 # or more complex ;)\r
1252   $ print -l ${^path}/*(Ns,S)\r
1253 # or show only executables with a user given pattern\r
1254   $ print -l ${^path}/*vim*(*N)\r
1255 \r
1256 # gzip files when containing a certain string\r
1257   $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}\r
1258 \r
1259 # A small  one-liner, that reads from stdin and prints to stdout the first\r
1260 # unique line i. e. does not print lines that have been printed before\r
1261 # (this is similar to the unique command, but unique can only handle\r
1262 # adjacent lines).\r
1263   $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}\r
1264 \r
1265 # Lists every executable in PATH\r
1266   $ print -l ${^path}/*(-*N)\r
1267 \r
1268 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?\r
1269   $ ls **/*.c~(*/)#SCCS/*\r
1270 \r
1271 # List all `README' - files case-insensitive with max. one typo\r
1272   $ ls **/*(#ia2)readme\r
1273 \r
1274 # case insensitive checking for variables\r
1275   $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then\r
1276   &gt;    echo "Penguin on board."\r
1277   &gt; else\r
1278   &gt;    echo "Not a Linux."\r
1279   &gt; fi</code></pre>\r
1280 </div></div>\r
1281 </div>\r
1282 <div class="sect2">\r
1283 <h3 id="_recursive_globbing_examples">(Recursive) Globbing - Examples</h3>\r
1284 <div class="paragraph"><p>A list of valid glob Qualifiers can be found in zshexpn(1). <strong>Note:</strong>\r
1285 **/ is equivalent to (*/)#! For example:</p></div>\r
1286 <div class="listingblock">\r
1287 <div class="content">\r
1288 <pre><code>$ print (*/)#zsh_us.ps\r
1289 zsh-4.2.3/Doc/zsh_us.ps\r
1290 $ print **/zsh_us.ps\r
1291 zsh-4.2.3/Doc/zsh_us.ps</code></pre>\r
1292 </div></div>\r
1293 <div class="listingblock">\r
1294 <div class="content">\r
1295 <pre><code># Search for `README' in all Subdirectories\r
1296   $ ls -l **/README\r
1297 \r
1298 # find directories that contain both "index.php" and "index.html", or in\r
1299 # general, directories that contain more than one file matching "index.*"\r
1300   $ ls **/*(D/e:'[[ -e $REPLY/index.php &amp;&amp; -e $REPLY/index.html ]]':)\r
1301   # or\r
1302   $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l &gt;= 2 ))':)\r
1303 \r
1304 # Find command to search for directory name instead of basename\r
1305   $ print -rl /**/*~^*/path(|/*)\r
1306   # or - without Zsh\r
1307   $ find / | grep -e /path/ -e '/path$'\r
1308 \r
1309 # Print he path of the directories holding the ten biggest C regular files\r
1310 # in the current directory and subdirectories.\r
1311   $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u\r
1312 \r
1313 # Find files with size == 0 and send a mail\r
1314   $ files=(**/*(ND.L0m+0m-2))\r
1315   &gt; (( $#files &gt; 0 )) &amp;&amp; print -rl -- $files | \\r
1316     mailx -s "empty files" foo@bar.tdl\r
1317 \r
1318 # recursive chmod\r
1319   $ chmod 700 **/(.) # Only files\r
1320   $ chmod 700 **/(/) # Only directories\r
1321 \r
1322 # print out all of the files in that directory in 2 columns\r
1323   $ print -rC2 -- ${1:[...]}/*(D:t)\r
1324 #            ^- number ob columns\r
1325 # or - if you feel concerned about special characters - use\r
1326   $ list=(${1:[...]}/*(ND:t))\r
1327   $ (($#list)) &amp;&amp; print -rC2 -- ${(V)list}\r
1328 \r
1329 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag\r
1330 # (recursive, include  dotfiles) remove the setgid/setuid flag and print\r
1331 # a message\r
1332   $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))\r
1333 # or with a small script\r
1334   $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {\r
1335   &gt;    print -r -- $file\r
1336   &gt;    chmod -s $file &amp;&amp; print -r fixed $file\r
1337   &gt; }\r
1338 # or use ``zargs'' (require autoload zargs) prevent the arg list too\r
1339 # long error\r
1340   $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s\r
1341 \r
1342 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)\r
1343   $ ls -l foo&lt;23-&gt;\r
1344 \r
1345 # get all files that begin with the date strings from June 4 through\r
1346 # June 9 of 2004\r
1347   $ ls -l 200406{04..10}*(N)\r
1348 # or if they are of the form 200406XX (require ``setopt extended_glob''\r
1349   $ ls -l 200306&lt;4-10&gt;.*\r
1350 \r
1351 # remove spaces from filenames\r
1352   $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done\r
1353 \r
1354 # Show only all *.c and *.h - Files\r
1355   $ ls -l *.(c|h)\r
1356 \r
1357 # Show only all *.c - files and ignore `foo.c'\r
1358   $ ls *.c~foo.c\r
1359 \r
1360 # show data to *really* binary format\r
1361   $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \\r
1362   &gt; {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' &lt; binary\r
1363 \r
1364 # Show only world-readable files\r
1365   $ ls -l *(R)\r
1366 \r
1367 # List files in the current directory are not writable by the owner\r
1368   $ print -l ~/*(ND.^w)\r
1369 \r
1370 # find and delete the files which are older than a given parameter\r
1371 # (seconds/minutes/hours)\r
1372   # deletes all regular file in /Dir that are older than 3 hours\r
1373    $ rm -f /Dir/**/*(.mh+3)\r
1374   # deletes all symlinks in /Dir that are older than 3 minutes\r
1375    $ rm -f /Dir/**/*(@mm+3)\r
1376   # deletes all non dirs in /Dir that are older than 30 seconds\r
1377    $ rm -f /Dir/**/*(ms+30^/)\r
1378   # deletes all folders, sub-folders and files older than one hour\r
1379    $ rm ./**/*(.Dmh+1,.DL0)\r
1380   # deletes all files more than 6 hours old\r
1381    $ rm -f **/*(mh+6)\r
1382   # removes all files but the ten newer ones (delete all but last 10\r
1383   # files in a directory)\r
1384    $ rm ./*(Om[1,-11])\r
1385  Note: If you get a arg list too long, you use the builtin rm. For\r
1386        example:\r
1387    $ zmodload zsh/files ; rm -f **/*(mh+6)\r
1388   or use the zargs function:\r
1389    $ autoload zargs ; zargs **/*(mh+6) -- rm -f\r
1390 \r
1391 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern\r
1392 # Matching find all files in all subdirectories, searching recursively,\r
1393 # which have a given name, case insensitive, are at least 50 KB large,\r
1394 # no more than a week old and owned by the root user, and allowing up\r
1395 # to a single error in the spelling of the name. In fact, the required\r
1396 # expression looks like this:\r
1397   $ ls **/(#ia1)name(LK+50mw-1u0)\r
1398 \r
1399 # Change the UID from 102 to 666\r
1400   $ chown 666 **/*(u102)\r
1401 \r
1402 # List all files which have not been updated since last 10 hours\r
1403   $ print -rl -- *(Dmh+10^/)\r
1404 \r
1405 # delete only the oldest file in a directory\r
1406   $ rm ./*filename*(Om[1])\r
1407 \r
1408 # Sort the output from `ls -l' by file size\r
1409   $ ls -fld *(OL)\r
1410 \r
1411 # find most recent file in a directory\r
1412   $ setopt dotglob ; print directory/**/*(om[1])\r
1413 \r
1414 # Show only empty files which nor `group' or `world writable'\r
1415   $ ls *(L0f.go-w.)\r
1416 \r
1417 # Find - and list - the ten newest files in directories and subdirs.\r
1418 # (recursive)\r
1419   $ print -rl -- **/*(Dom[1,10])\r
1420 \r
1421 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'').\r
1422   $ ls -fl *(DOL[1,5])\r
1423 \r
1424 # Display the 5-10 last modified files.\r
1425   $ print -rl -- /path/to/dir/**/*(D.om[5,10])\r
1426 \r
1427 # Find all files without a valid owner.\r
1428   $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(&lt;/etc/passwd)"}%%:*}:)\r
1429 \r
1430 # Find all the empty directories in a tree.\r
1431   $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] &amp;&amp; print $f; done\r
1432 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.\r
1433 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all\r
1434 # subdirectories with no entries.\r
1435   $ ls -ld *(/^F)\r
1436 \r
1437 # Remove empty directories afterwards.\r
1438   $ rmdir ./**/*(/od) 2&gt; /dev/null\r
1439 \r
1440 # Show only files which are owned by group `users'.\r
1441   $ ls -l *(G[users])</code></pre>\r
1442 </div></div>\r
1443 </div>\r
1444 <div class="sect2">\r
1445 <h3 id="_modifiers_usage">Modifiers usage</h3>\r
1446 <div class="paragraph"><p>Modifiers are a powerful mechanism that let you modify the results\r
1447 returned by parameter, filename and history expansion. See zshexpn(1)\r
1448 for details.</p></div>\r
1449 <div class="listingblock">\r
1450 <div class="content">\r
1451 <pre><code># NOTE: Zsh 4.3.4 needed!\r
1452   $ autoload -U age\r
1453 # files modified today\r
1454   $ print *(e:age today now:)\r
1455 # files modified since 5 pm\r
1456   $ print *(e-age 17:00 now-)\r
1457 # ... since 5 o'clock yesterda\r
1458   $ print *(e-age yesterday,17:00 now-)\r
1459 # ... from last Christmas before today\r
1460   $ print *(e-age 2006/12/25 today-)\r
1461 # ... before yesterday\r
1462   $ print *(e-age 1970/01/01 yesterday-)\r
1463 # all files modified between the start of those dates\r
1464   $ print *(e:age 2006/10/04 2006/10/09:)\r
1465 # all files modified on that date\r
1466   $ print *(e:age 2006/10/04:)\r
1467 # Supply times.\r
1468   $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)\r
1469 \r
1470 # Remove a trailing pathname component, leaving the head. This works like\r
1471 # `dirname'.\r
1472   $ echo =ls(:h)\r
1473   /bin\r
1474 \r
1475 # Remove all leading pathname components, leaving the tail. This works\r
1476 # like `basename'.\r
1477   $ echo =ls(:t)\r
1478   ls\r
1479 \r
1480 # Remove the suffix from each file (*.sh in this example)\r
1481    $f:e is $f file extension\r
1482    :h --&gt; head (dirname)\r
1483    :t --&gt; tail (basename)\r
1484    :r --&gt; rest (extension removed)\r
1485   $ for f (*.sh) mv $f $f:r\r
1486 \r
1487 # Remove a filename extension of the form `.xxx', leaving the root name.\r
1488   $ echo $PWD\r
1489   /usr/src/linux\r
1490   $ echo $PWD:t\r
1491   linux\r
1492 \r
1493 # Remove all but the extension.\r
1494   $ foo=23.42\r
1495   $ echo $foo\r
1496   23.42\r
1497   $ echo $foo:e\r
1498   42\r
1499 \r
1500 # Print the new command but do not execute it. Only works with history\r
1501 # expansion.\r
1502   $ echo =ls(:h)\r
1503   /bin\r
1504   $ !echo:p\r
1505   $ echo =ls(:h)\r
1506 \r
1507 # Quote the substituted words, escaping further substitutions.\r
1508   $ bar="23'42"\r
1509   $ echo $bar\r
1510   23'42\r
1511   $ echo $bar:q\r
1512   23\'42\r
1513 \r
1514 # Convert the words to all lowercase.\r
1515   $ bar=FOOBAR\r
1516   $ echo $bar\r
1517   FOOBAR\r
1518   $ echo $bar:l\r
1519   foobar\r
1520 \r
1521 # Convert the words to all uppercase.\r
1522   $ bar=foobar\r
1523   $ echo $bar\r
1524   foobar\r
1525   $ echo $bar:u\r
1526   FOOBAR\r
1527 \r
1528 # convert 1st char of a word to uppercase\r
1529   $ foo="one two three four"\r
1530   $ print -r -- "${(C)foo}"\r
1531   One Two Three Four</code></pre>\r
1532 </div></div>\r
1533 </div>\r
1534 <div class="sect2">\r
1535 <h3 id="_redirection_examples">Redirection-Examples</h3>\r
1536 <div class="paragraph"><p>See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))</p></div>\r
1537 <div class="listingblock">\r
1538 <div class="content">\r
1539 <pre><code># Append `exit 1' at the end of all *.sh - files\r
1540   $ echo "exit 1" &gt;&gt; *.sh\r
1541 \r
1542 # adding files to foobar.tar.gz\r
1543   $ eval set =(gunzip &lt; foobar.tar.gz) '\r
1544      tar rf $1 additional.txt &amp;&amp;gzip &lt; $1 &gt; foobar.tar.gz'\r
1545 \r
1546 # Redirect output to a file AND display on screen\r
1547   $ foobar &gt;&amp;1 &gt; file1 &gt; file2 &gt; ..\r
1548 \r
1549 # pipe single output to multiple inputs\r
1550   $ zcat foobar.Z &gt;&gt; (gzip -9 &gt; file1.gz) \\r
1551       &gt;&gt; (bzip2 -9 &gt; file1.bz2) \\r
1552       &gt;&gt; (acb --best &gt; file1.acb)\r
1553 \r
1554 # Append /etc/services at the end of file `foo' and `bar'\r
1555   $ cat /etc/services &gt;&gt; foo &gt;&gt; bar\r
1556 \r
1557 # Pipe STDERR\r
1558   $ echo An error &gt;&amp;2 2&gt;&amp;1 | sed -e 's/A/I/'\r
1559 \r
1560 # send standard output of one process to standard input of several processes\r
1561 # in the pipeline\r
1562   $ setopt multios\r
1563   $ process1 &gt; &gt;(process1) &gt; &gt;(process2)\r
1564 \r
1565 # initializing a variable and simultaneously keeping terminal output\r
1566   $ setopt multios\r
1567   $ { a=$(command &gt;&amp;1 &gt;&amp; 3 3 &gt; &amp;- 2&gt;&amp;1);} 3&gt;&amp;1\r
1568 \r
1569 # redirect stderr two times\r
1570   $ setopt multios ; program 2&gt; file2 &gt; file1 2&gt;&amp;1\r
1571 \r
1572 # Duplicating stdout and stderr to a logfile\r
1573   $ exec 3&gt;&amp;1 &gt; logfile 2&gt;&amp;2 2&gt;&amp;1 &gt;&amp;3 3&gt;&amp;-\r
1574 \r
1575 # redirect stderr (only) to a file and to orig. stderr:\r
1576   $ command 2&gt;&amp;2 2&gt;stderr\r
1577 # redirect stderr and stdout to separate files and both to orig. stdout:\r
1578   $ command 2&gt;&amp;1 1&gt;&amp;1 2&gt;stderr 1&gt;stdout\r
1579 # redirect stderr and stdout to separate files and stdout to orig. stdout\r
1580 # AND stderr to orig. stderr:\r
1581   $ command 2&gt;&amp;2 1&gt;&amp;1 2&gt;stderr 1&gt;stdout\r
1582 \r
1583 # More fun with STDERR ;)\r
1584   $ ./my-script.sh 2&gt; &gt;(grep -v moron &gt;error.log)|process-output &gt;output.log\r
1585   $  echo "Thats STDOUT" &gt;&gt;(sed 's/stdout/another example/' &gt; foobar)</code></pre>\r
1586 </div></div>\r
1587 </div>\r
1588 <div class="sect2">\r
1589 <h3 id="_zmv_examples_require_autoload_zmv">ZMV-Examples (require autoload zmv)</h3>\r
1590 <div class="paragraph"><p><strong>Note:</strong> <em>-n</em> means no execution (just print what would happen). At</p></div>\r
1591 <div class="listingblock">\r
1592 <div class="content">\r
1593 <pre><code># Remove illegal characters in a fat32 file system. Illegal characters are\r
1594 #   / :  ;  *  ?  "  &lt;  &gt;  |\r
1595 # NOTE: ``-Q'' and (D) is to include hidden files.\r
1596   $ unwanted='[:;*?\"&lt;&gt;|]'\r
1597   $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'\r
1598 \r
1599 # Changing part of a filename (i. e. "file-hell.name" -&gt; "file-heaven.name")\r
1600   $ zmv '(*)hell(*)' '${1}heaven${2}'\r
1601   # or\r
1602   $ zmv '*' '$f:s/hell/heaven/'\r
1603 \r
1604 # remove round bracket within filenames\r
1605 # i. e. foo-(bar).avi -&gt; foo-bar.avi\r
1606   $ zmv '*' '${f//[()]/}'\r
1607 \r
1608 # serially all files (foo.foo &gt; 1.foo, fnord.foo &gt; 2.foo, ..)\r
1609   $ autoload zmv\r
1610   $ ls *\r
1611   1.c  asd.foo  bla.foo  fnord.foo  foo.fnord  foo.foo\r
1612   $ c=1 zmv '*.foo' '$((c++)).foo'\r
1613   $ ls *\r
1614   1.c  1.foo  2.foo  3.foo  4.foo  foo.fnord\r
1615 \r
1616 # Rename "file.with.many.dots.txt" by substituting dots (exept for the last\r
1617 # one!) with a space\r
1618   $ touch {1..20}-file.with.many.dots.txt\r
1619   $ zmv '(*.*)(.*)' '${1//./ }$2'\r
1620 \r
1621 # Remove the first 4 chars from a filename\r
1622   $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!\r
1623 \r
1624 # Rename names of all files under the current Dir to lower case, but keep\r
1625 # dirnames as-is.\r
1626   $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'\r
1627 \r
1628 # replace all 4th character, which is "1",  with "2" and so on\r
1629   $ autoload -U zmv\r
1630   $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'\r
1631 \r
1632 # Remove the first 15 characters from a string\r
1633   $ touch 111111111111111{a-z}\r
1634   $ autoload zmv\r
1635   $ zmv '*' '$f[16,-1]'\r
1636 \r
1637 # Replace spaces (any number of them) with a single dash in file names\r
1638   $ autload zmv\r
1639   $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'\r
1640   # or - with Bash\r
1641   $ find . -depth -name '* *' -exec bash -c '\r
1642   &gt; shopt -s extglob\r
1643   &gt; file=$1\r
1644   &gt; dir=${file%/*}\r
1645   &gt; name=${file##*/}\r
1646   &gt; newname=${name//*([ -]) *([ -])/-}\r
1647   &gt; mv -i -- "$file" "$Dir/$newname"' {} {} \;\r
1648 \r
1649 # Clean up file names and remove special characters\r
1650   $ autoload zmv\r
1651   $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'\r
1652 \r
1653 # Add *.py to a bunch of python scripts in a directory (some of them end\r
1654 # in *.py and give them all a proper extension\r
1655   $ autoload zmv\r
1656   $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'\r
1657 \r
1658 # lowercase all extensions (i. e. *.JPG) incl. subfolders\r
1659   $ autoload zmv\r
1660   $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'\r
1661   # Or - without Zsh\r
1662   $ find Dir -name '*.[jJ][pP][gG]' -print | while read f\r
1663   &gt; do\r
1664   &gt;      case $f in\r
1665   &gt;       *.jpg) ;\r
1666   &gt;       *) mv "$f" "${f%.*}.jpg" ;\r
1667   &gt;       esac\r
1668   &gt; done\r
1669 \r
1670 # remove leading zeros from file extension\r
1671   $ autoload zmv\r
1672   $ ls\r
1673   filename.001  filename.003  filename.005  filename.007  filename.009\r
1674   filename.002  filename.004  filename.006  filename.008  filename.010\r
1675   $ zmv '(filename.)0##(?*)' '$1$2'\r
1676   $ ls\r
1677   filename.1  filename.10  filename.2  filename.3  filename.4  filename.5 ..\r
1678 \r
1679 # renumber files.\r
1680   $ autoload zmv\r
1681   $ ls *\r
1682   foo_10.jpg  foo_2.jpg  foo_3.jpg  foo_4.jpg  foo_5.jpg  foo_6.jpg ..\r
1683   $ zmv -fQ 'foo_(&lt;0-&gt;).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'\r
1684   $ ls *\r
1685   foo_10.jpg  foo_11.jpg  foo_3.jpg  foo_4.jpg  foo_5.jpg  ...\r
1686 \r
1687 # adding leading zeros to a filename (1.jpg -&gt; 001.jpg, ..\r
1688   $ autoload zmv\r
1689   $ zmv '(&lt;1-&gt;).jpg' '${(l:3::0:)1}.jpg'\r
1690 \r
1691 # See above, but now only files with a filename &gt;= 30 chars\r
1692   $ autoload zmv\r
1693   $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'\r
1694 \r
1695 # Replace spaces in filenames with a underline\r
1696   $ autoload zmv\r
1697   $ zmv '* *' '$f:gs/ /_'\r
1698 \r
1699 # Change the suffix from *.sh to *.pl\r
1700   $ autoload zmv\r
1701   $ zmv -W '*.sh' '*.pl'\r
1702 \r
1703 # Add a "".txt" extension to all the files within ${HOME}\r
1704   # ``-.'' is to only rename regular files or symlinks to regular files,\r
1705   # ``D'' is to also rename hidden files (dotfiles))\r
1706   $ autoload zmv\r
1707   $ zmv -Q '/home/**/*(D-.)' '$f.txt'\r
1708   # Or to only rename files that don't have an extension:\r
1709   $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'\r
1710 \r
1711 # Recursively change filenames with characters ? [ ] / = + &lt; &gt; ; : " , - *\r
1712   $ autoload zmv\r
1713   $ chars='[][?=+&lt;&gt;;",*-]'\r
1714   $ zmv '(**/)(*)' '$1${2//$~chars/%}'\r
1715 \r
1716 # Removing single quote from filenames (recursively)\r
1717   $ autoload zmv\r
1718   $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"\r
1719 \r
1720 # When a new file arrives (named file.txt) rename all files in order to\r
1721 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes\r
1722 # file119.txt and so on ending with file.txt becoming file1.txt\r
1723   $ autoload zmv\r
1724   $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'\r
1725 \r
1726 # lowercase/uppercase all files/directories\r
1727   $ autoload zmv\r
1728   $ zmv '(*)' '${(L)1}' # lowercase\r
1729   $ zmv '(*)' '${(U)1}' # uppercase\r
1730 \r
1731 # Remove the suffix *.c from all C-Files\r
1732   $ autoload zmv\r
1733   $ zmv '(*).c' '$1'\r
1734 \r
1735 # Uppercase only the first letter of all *.mp3 - files\r
1736   $ autoload zmv\r
1737   $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'\r
1738 \r
1739 # Copy the target `README' in same directory as each `Makefile'\r
1740   $ autoload zmv\r
1741   $ zmv -C '(**/)Makefile' '${1}README'\r
1742 \r
1743 # Removing single quote from filenames (recursively)\r
1744   $ autoload zmv\r
1745   $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"\r
1746 \r
1747 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..\r
1748   $ autoload zmv\r
1749   $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'\r
1750   $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively</code></pre>\r
1751 </div></div>\r
1752 </div>\r
1753 <div class="sect2">\r
1754 <h3 id="_module_examples">Module-Examples</h3>\r
1755 <div class="paragraph"><p>Please read zshmodules(1) first!</p></div>\r
1756 <div class="sect3">\r
1757 <h4 id="_zsh_pcre_require_zmodload_zsh_pcre">zsh/pcre (require zmodload zsh/pcre)</h4>\r
1758 <div class="listingblock">\r
1759 <div class="content">\r
1760 <pre><code># Copy files of a certain period (date indicated in the filenames)\r
1761   $ zmodload zsh/pcre\r
1762   $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)\r
1763   # or\r
1764   $ m() { [[ $1 -pcre-match pcre-regexp ]] }\r
1765   $ ls -d -- *(+m)</code></pre>\r
1766 </div></div>\r
1767 </div>\r
1768 <div class="sect3">\r
1769 <h4 id="_zsh_clone_require_zmodload_zsh_clone">zsh/clone (require zmodload zsh/clone)</h4>\r
1770 <div class="listingblock">\r
1771 <div class="content">\r
1772 <pre><code># Creates a forked instance of the current shell ($! is set to zero) and\r
1773 # execute ``command'' on /dev/tty8 (for this example).\r
1774   $ zmodload zsh/clone\r
1775   $ clone /dev/tty8 &amp;&amp; (($! == 0)) &amp;&amp; exec command</code></pre>\r
1776 </div></div>\r
1777 </div>\r
1778 <div class="sect3">\r
1779 <h4 id="_zsh_datetime_require_zmodload_zsh_datetime">zsh/datetime (require zmodload zsh/datetime)</h4>\r
1780 <div class="listingblock">\r
1781 <div class="content">\r
1782 <pre><code>  $ zmodload zsh/datetime\r
1783   $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'\r
1784   $ export DATE=`datereplacement`\r
1785   $ echo $DATE\r
1786 \r
1787 #  strip date from filename\r
1788   $ $ zmodload zsh/datetime\r
1789   $ setopt extendedglob\r
1790   $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat\r
1791   $ strftime -s pattern \\r
1792     '???_???_&lt;0-%Y%m%d&gt;_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))\r
1793   $ print -rl -- $~pattern\r
1794   aaa_bbb_20041212_c.dat\r
1795   $ print -rl -- $pattern\r
1796   ???_???_&lt;0-20050815&gt;_?.dat\r
1797 \r
1798 # Search files size == 0, to be based on the file name containing a date\r
1799 # rather than the "last modified" date of the file\r
1800   $ zmodload -i zsh/datetime\r
1801   $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))\r
1802   $ files=(**/$file(N.L0))\r
1803   $ (( $#files &gt; 0 )) &amp;&amp; print -rl -- $files | \\r
1804     mailx -s "empty files"  foo@bar.tdl</code></pre>\r
1805 </div></div>\r
1806 </div>\r
1807 <div class="sect3">\r
1808 <h4 id="_zsh_stat_require_zmodload_zsh_stat">zsh/stat (require zmodload zsh/stat)</h4>\r
1809 <div class="listingblock">\r
1810 <div class="content">\r
1811 <pre><code># test if a symbolic link links to a certain file\r
1812   $ zmodload -i zsh/stat\r
1813   $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln\r
1814 \r
1815 # comparing file dates\r
1816   $ zmodload zsh/stat\r
1817   $ file1=foo\r
1818   $ file2=bar\r
1819   $ touch bar &amp; sleep 5 &amp; touch foo\r
1820   $ echo $file1 is $(($(stat +mtime $file2) - \\r
1821     $(stat +mtime $file1))) seconds older than $file2.\r
1822   bar is 5 seconds older than foo\r
1823 \r
1824 # list the files of a disk smaller than some other file\r
1825   $ zmodload zsh/stat\r
1826   $ stat -A max +size some-other-file\r
1827   $ print -rl ./**/*(D.L-$max)\r
1828 \r
1829 # List the top 100 biggest files in a disk\r
1830   $ zmodload zsh/stat\r
1831   $ ls -fld ./**/*(d`stat +device .`OL[1,100])\r
1832 \r
1833 # Get only the user name and the file names from (like\r
1834 # ls -l * | awk '{print $3" " $8}')\r
1835   $ zmodload zsh/stat\r
1836   $ for file; do\r
1837   &gt;   stat -sA user +uid -- "$file" &amp;&amp;\r
1838   &gt;     print -r -- "$user" "$file"\r
1839   &gt; done\r
1840 \r
1841 # get the difference between actual bytes of file and allocated bytes of file\r
1842   $ zmodload zsh/stat\r
1843   $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))\r
1844 \r
1845 # Find largest file\r
1846 # ``D''  : to include dot files (d lowercase is for device)\r
1847 # ``O''  : reverse Ordered (o lowercase for non-reverse order)\r
1848 # ``L''  : by file Length (l is for number of links)\r
1849 # ``[1]'': return only first one\r
1850   $ zmodload zsh/stat\r
1851   $ stat +size ./*(DOL[1])\r
1852 \r
1853 # file size in bytes\r
1854   $ zmodload zsh/stat\r
1855   $ stat -L +size ~/.zshrc\r
1856   4707\r
1857 \r
1858 # Delete files in a directory that hasn't been accessed in the last ten days\r
1859 # and send ONE mail to the owner of the files informing him/her of the files'\r
1860 # deletion.\r
1861   $ zmodload zsh/stat zsh/files\r
1862   $ typeset -A f; f=()\r
1863   $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})\r
1864   $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}\r
1865 \r
1866 # Get a "ls -l" on all the files in the tree that are younger than a\r
1867 # specified age\r
1868   $ zmodload zsh/stat\r
1869   $ for d (. ./**/*(N/m-2))\r
1870   &gt;   print -r -- $'\n'$d: &amp;&amp; cd $d &amp;&amp; {\r
1871   &gt;      for f (*(Nm-2om))\r
1872   &gt;   stat -F '%b %d %H:%M' -LsAs -- $f &amp;&amp;\r
1873   &gt;   print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \\r
1874   &gt;   ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-&gt; $s[14]}\r
1875   &gt;   cd ~-\r
1876   &gt; }\r
1877 \r
1878 # get file creation date\r
1879   $ zmodload zsh/stat\r
1880   $ stat -F '%d %m %Y' +mtime ~/.zshrc\r
1881   30 06 2004\r
1882   $ stat -F '%D' +mtime ~/.zshrc\r
1883   06/30/04</code></pre>\r
1884 </div></div>\r
1885 </div>\r
1886 <div class="sect3">\r
1887 <h4 id="_zsh_files_require_zmodload_zsh_files">zsh/files (require zmodload zsh/files)</h4>\r
1888 <div class="listingblock">\r
1889 <div class="content">\r
1890 <pre><code># search a directory for files containing a certain string then copy those\r
1891 # files to another directory.\r
1892   $ zmodload zsh/files\r
1893   $ IFS=$'\0'\r
1894   $ cp $(grep -lZr foobar .) otherdirectory</code></pre>\r
1895 </div></div>\r
1896 </div>\r
1897 <div class="sect3">\r
1898 <h4 id="_zsh_mapfile_require_zmodload_zsh_mapfile">zsh/mapfile (require zmodload zsh/mapfile)</h4>\r
1899 <div class="listingblock">\r
1900 <div class="content">\r
1901 <pre><code># grepping for two patterns\r
1902   $ zmodload zsh/mapfile\r
1903   $ pattern1="foo"\r
1904   $ pattern2="bar foo"\r
1905   $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] &amp;&amp; [[ $z = *$pattern1* &amp;&amp; \\r
1906     $z = *$pattern2* ]]'})\r
1907 # or a solution in combination with zsh/pcre\r
1908   $ zmodload -i zsh/mapfile zsh/pcre\r
1909   $ pattern1="foo"\r
1910   $ pattern2="bar foo"\r
1911   $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"\r
1912   $ pcre_study\r
1913   $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})\r
1914 \r
1915 # equivalent for ``less /etc/passwd | grep -v root''\r
1916   $ zmodload zsh/mapfile\r
1917   $ IFS=$'\n\n'\r
1918   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}\r
1919 # or - for case insensitive\r
1920   $ setopt extendedglob\r
1921   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}\r
1922 \r
1923 # If a XML-file contains stuff like ``&lt;TAGA/&gt;'' and ``&lt;TAGB/&gt;'', number\r
1924 # this empty tags (ones ending in '/&gt;') so if encountered in the same\r
1925 # order, the preceeding tags would become ``&lt;TAGA/&gt;1&lt;/TAGA&gt;'' and\r
1926 # ``&lt;TAGB/&gt;2&lt;/TAGB&gt;''\r
1927   $ zmodload zsh/mapfile\r
1928   $ cnt=0\r
1929   $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\\r
1930   &gt; (#im)&lt;TAGA&gt;*&lt;\/TAGA&gt;/&lt;TAGA&gt;$((++cnt))&lt;\/TAGA&gt;}\r
1931 \r
1932 # removing all files in users Maildir/new that contain ``filename="gone.src''\r
1933   $ zmodload zsh/{files,mapfile}\r
1934   $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \\r
1935     *filename=\"gone.scr\"* ]]'})\r
1936 \r
1937 # Grep out the Title from a postscript file and append that value to the\r
1938 # end of the filename\r
1939   $ autoload -U zmv\r
1940   $ zmodload zsh/mapfile\r
1941   $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'</code></pre>\r
1942 </div></div>\r
1943 </div>\r
1944 <div class="sect3">\r
1945 <h4 id="_zsh_mathfunc_require_zmodload_zsh_mathfunc">zsh/mathfunc (require zmodload zsh/mathfunc)</h4>\r
1946 <div class="listingblock">\r
1947 <div class="content">\r
1948 <pre><code>$ zmodload zsh/mathfunc\r
1949 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))\r
1950   -1.1102230246251565e-16\r
1951 $ echo $(( pi = 4.0 * atan(1.0) ))\r
1952   3.1415926535897931\r
1953 $ echo $(( f = sin(0.3) ))\r
1954   0.29552020666133955\r
1955 $ print $((1e12 * rand48()))\r
1956   847909677310.23413\r
1957 $ print $(( rand48(seed) ))\r
1958   0.01043488334700271</code></pre>\r
1959 </div></div>\r
1960 </div>\r
1961 <div class="sect3">\r
1962 <h4 id="_zsh_termcap_require_zmodload_zsh_termcap">zsh/termcap (require zmodload zsh/termcap)</h4>\r
1963 <div class="listingblock">\r
1964 <div class="content">\r
1965 <pre><code> $ zmodload -ab zsh/termcap echotc\r
1966  $ GREEN=`echotc AF 2`\r
1967  $ YELLOW=`echotc AF 3`\r
1968  $ RED=`echotc AF 1`\r
1969  $ BRIGHTRED=`echotc md ; echotc AF 1`\r
1970  $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred</code></pre>\r
1971 </div></div>\r
1972 </div>\r
1973 <div class="sect3">\r
1974 <h4 id="_zsh_zpty_require_zmodload_zsh_zpty">zsh/zpty (require zmodload zsh/zpty)</h4>\r
1975 <div class="listingblock">\r
1976 <div class="content">\r
1977 <pre><code>  $ zmodload zsh/zpty\r
1978   $ zpty PW passwd $1\r
1979   $ zpty PW passwd $1\r
1980 # ``-r'': read the output of the command name.\r
1981 # ``z'' : Parameter\r
1982   $ zpty -r PW z '*password:'\r
1983 # send the to command name the given strings as input\r
1984   $ zpty -w PW $2\r
1985   $ zpty -r PW z '*password:'\r
1986   $ zpty -w PW $2\r
1987 # The second form, with the -d option, is used to delete commands\r
1988 # previously started, by supplying a list of their names. If no names\r
1989 # are given, all commands are deleted. Deleting a command causes the HUP\r
1990 # signal to be sent to the corresponding process.\r
1991   $ zpty -d PW</code></pre>\r
1992 </div></div>\r
1993 </div>\r
1994 <div class="sect3">\r
1995 <h4 id="_zsh_net_socket_require_zmodload_zsh_net_socket">zsh/net/socket (require zmodload zsh/net/socket)</h4>\r
1996 <div class="listingblock">\r
1997 <div class="content">\r
1998 <pre><code># ``-l'': open a socket listening on filename\r
1999 # ``-d'': argument will be taken as the target file descriptor for the\r
2000 #         connection\r
2001 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''\r
2002 #         (3.7.2: File descriptors)\r
2003   $ zmodload zsh/net/socket\r
2004   $ zsocket -l -d 3\r
2005 # ``-a'': accept an incoming connection to the socket\r
2006   $ zsocket -a -d 4 3\r
2007   $ zsocket -a -d 5 3 # accept a connection\r
2008   $ echo foobar &gt;&amp;4\r
2009   $ echo barfoo &gt;&amp;5\r
2010   $ 4&gt;&amp;- 5&gt;&amp;- 3&gt;&amp;</code></pre>\r
2011 </div></div>\r
2012 </div>\r
2013 <div class="sect3">\r
2014 <h4 id="_zsh_zftp_require_zmodload_zsh_zftp">zsh/zftp (require zmodload zsh/zftp)</h4>\r
2015 <div class="listingblock">\r
2016 <div class="content">\r
2017 <pre><code> $ autoload -U zfinit\r
2018  $ zfinit\r
2019  $ zfparams www.example.invalid myuserid mypassword\r
2020  $ zfopen\r
2021  $ zfcd tips\r
2022  $ zfls -l zshtips.html\r
2023  $ zfput zshtips.html\r
2024  $ zfls -l zshtips.html\r
2025 \r
2026 # Automatically transfer files using FTP with error checking\r
2027   $ autoload -U zfinit ; zfinit\r
2028   $ zftp open host.name.invalid user passwd || exit\r
2029   $ zftp get /remote/file &gt; /local/file; r=$?\r
2030   $ zftp close &amp;&amp; exit r\r
2031 \r
2032 # compress and ftp on the fly\r
2033   $ autoload -U zfinit ; zfinit\r
2034   $ zftp open host.name.invalid user password\r
2035   $ zftp get $file | bzip2 &gt; ${file}.bz2\r
2036   $ zftp close\r
2037 \r
2038 # Recursice ``get''\r
2039   $ autoload -U zfinit ; zfinit\r
2040   $ zfanon cr.yp.to\r
2041   $ zfcd daemontools\r
2042   $ for file in `zfls` ; do\r
2043   &gt;     zfget $file\r
2044   $ done\r
2045   $ zfclose\r
2046 \r
2047 # Upload all regular files in $HOME/foobar (recursive) that are newer than\r
2048 # two hours to ftp.foobar.invalid/path/to/upload\r
2049   $ autoload -U zfinit ; zfinit\r
2050   $ zfopen ftp.foobar.invalid/path/to/upload\r
2051   $ cd $HOME/foobar\r
2052   $ zfput -r **/*(.mh-2)\r
2053   $ zfclose\r
2054 \r
2055 # long list of files on a ftp\r
2056   $ autoload -U zfinit ; zfinit\r
2057   $ zfopen some-host\r
2058   $ zfcd /some/remote/Dir\r
2059   $ cd /some/local/Dir\r
2060 # If the list.txt is located on the remote host, change to\r
2061 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}\r
2062   $ zfget ${(f)"$(cat list.txt)"}\r
2063   $ zfclose</code></pre>\r
2064 </div></div>\r
2065 </div>\r
2066 <div class="sect3">\r
2067 <h4 id="_zsh_zselect_require_zmodload_zsh_zselect">zsh/zselect (require zmodload zsh/zselect)</h4>\r
2068 <div class="listingblock">\r
2069 <div class="content">\r
2070 <pre><code># It's similar to\r
2071  ,----\r
2072  | $ sg=$(stty -g)\r
2073  | $ stty -icanon min 0 time 50\r
2074  | $ read yesno\r
2075  | $ stty "$sg"\r
2076  | $ case "$yesno" in\r
2077  | &gt;  yes) command1;;\r
2078  | &gt;  *) command2;;\r
2079  | &gt; esac\r
2080  `----\r
2081 $ zmodload zsh/zselect\r
2082 $ if zselect -t 500 -r 0 &amp;&amp; read yesno &amp;&amp; [ yes = "$yesno" ]; then\r
2083 &gt;    command1\r
2084 &gt; else\r
2085 &gt;    command1\r
2086 &gt; fi</code></pre>\r
2087 </div></div>\r
2088 </div>\r
2089 </div>\r
2090 </div>\r
2091 </div>\r
2092 <div class="sect1">\r
2093 <h2 id="_options">OPTIONS</h2>\r
2094 <div class="sectionbody">\r
2095 <div class="sect2">\r
2096 <h3 id="_navigation_options">Navigation options</h3>\r
2097 <div class="paragraph"><p><strong>auto_cd</strong> (allow one to change to a directory by entering it as a\r
2098 command). <strong>auto_pushd</strong> (automatically append dirs to the push/pop list)\r
2099 pushd_ignore_dups (and don&#8217;t duplicate them).</p></div>\r
2100 </div>\r
2101 <div class="sect2">\r
2102 <h3 id="_misc">Misc</h3>\r
2103 <div class="paragraph"><p><strong>no_hup</strong> (don&#8217;t send  HUP signal to background jobs when exiting ZSH).\r
2104 <strong>print_exit_value</strong> (show a message with the exit code when a command\r
2105 returns with a non-zero exit code)</p></div>\r
2106 <div class="sect3">\r
2107 <h4 id="_history_options">History options</h4>\r
2108 <div class="paragraph"><p><strong>hist_verify</strong> (let the user edit the command line after history\r
2109 expansion (e.g. !ls) instead of immediately running it)<br />\r
2110 Use the same history file for all sessions :<br />\r
2111 <strong>setopt SHARE_HISTORY</strong></p></div>\r
2112 </div>\r
2113 <div class="sect3">\r
2114 <h4 id="_privacy_security">Privacy / Security</h4>\r
2115 <div class="paragraph"><p><strong>no_clobber</strong>  (or set -C; prevent <em>&gt;</em> redirection from truncating\r
2116 the given file if it already exists)</p></div>\r
2117 </div>\r
2118 <div class="sect3">\r
2119 <h4 id="_spelling_correction">Spelling correction</h4>\r
2120 <div class="paragraph"><p><strong>correct</strong> (automatically correct the spelling of commands).\r
2121 <strong>correct_all</strong> (automatically correct the spelling of each word on the\r
2122 command line) <strong>dvorak</strong> (dvorak layout)</p></div>\r
2123 </div>\r
2124 </div>\r
2125 </div>\r
2126 </div>\r
2127 <div class="sect1">\r
2128 <h2 id="_unsorted_misc">UNSORTED/MISC</h2>\r
2129 <div class="sectionbody">\r
2130 <div class="paragraph"><p>Mailpath: simple multiple mailpath:</p></div>\r
2131 <div class="listingblock">\r
2132 <div class="content">\r
2133 <pre><code>mailpath=($HOME/Mail/mbox'?new mail in mbox'\r
2134           $HOME/Mail/tux.u-strasbg'?new mail in tux'\r
2135           $HOME/Mail/lilo'?new mail in lilo'\r
2136           $HOME/Mail/ldap-fr'?new mail in ldap-fr')</code></pre>\r
2137 </div></div>\r
2138 <div class="paragraph"><p>Mailpath: dynamic mailpath:</p></div>\r
2139 <div class="listingblock">\r
2140 <div class="content">\r
2141 <pre><code>typeset -a mailpath\r
2142 for i in ~/Mail/Lists/*(.); do\r
2143    mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."\r
2144 done</code></pre>\r
2145 </div></div>\r
2146 <div class="paragraph"><p>Avoid globbing on special commands:</p></div>\r
2147 <div class="listingblock">\r
2148 <div class="content">\r
2149 <pre><code>for com in alias expr find mattrib mcopy mdir mdel which;\r
2150 alias $com="noglob $com"</code></pre>\r
2151 </div></div>\r
2152 <div class="paragraph"><p>For migrating your bashprompt to zsh use the script bash2zshprompt located in\r
2153 the zsh source distribution under <em>Misc</em>.</p></div>\r
2154 <div class="paragraph"><p>For migration from (t)csh to zsh use the c2z tool that converts csh\r
2155 aliases and environment and shell variables to zsh. It does this by running\r
2156 csh, and having csh report on aliases and variables. The script then converts\r
2157 these to zsh startup files. It has some issues and usage information that are\r
2158 documented at the top of this script.</p></div>\r
2159 <div class="paragraph"><p>Here are functions to set the title and hardstatus of an <strong>XTerm</strong> or of <strong>GNU\r
2160 Screen</strong> to <em>zsh</em> and the current directory, respectively, when the prompt is\r
2161 displayed, and to the command name and rest of the command line, respectively,\r
2162 when a command is executed:</p></div>\r
2163 <div class="listingblock">\r
2164 <div class="content">\r
2165 <pre><code>function title {\r
2166       if [[ $TERM == "screen" ]]; then\r
2167         # Use these two for GNU Screen:\r
2168         print -nR $' 33k'$1$' 33'\\r
2169         print -nR $' 33]0;'$2$''\r
2170       elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then\r
2171         # Use this one instead for XTerms:\r
2172         print -nR $' 33]0;'$*$''\r
2173       fi\r
2174 }\r
2175 function precmd { title zsh "$PWD" }\r
2176 function preexec {\r
2177     emulate -L zsh\r
2178     local -a cmd; cmd=(${(z)1})\r
2179     title $cmd[1]:t "$cmd[2,-1]"\r
2180 }</code></pre>\r
2181 </div></div>\r
2182 <div class="paragraph"><p>Put the following line into your ~/.screenrc to see this fancy hardstatus:</p></div>\r
2183 <div class="listingblock">\r
2184 <div class="content">\r
2185 <pre><code>caption always "%3n %t%? (%u)%?%?: %h%?"</code></pre>\r
2186 </div></div>\r
2187 <div class="paragraph"><p>Special variables which are assigned:</p></div>\r
2188 <div class="listingblock">\r
2189 <div class="content">\r
2190 <pre><code>$LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID\r
2191 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath</code></pre>\r
2192 </div></div>\r
2193 </div>\r
2194 </div>\r
2195 <div class="sect1">\r
2196 <h2 id="_links">LINKS</h2>\r
2197 <div class="sectionbody">\r
2198 <div class="dlist"><dl>\r
2199 <dt class="hdlist1">\r
2200 Primary site\r
2201 </dt>\r
2202 <dd>\r
2203 <p>\r
2204     <strong><a href="http://www.zsh.org/">http://www.zsh.org/</a></strong>\r
2205 </p>\r
2206 </dd>\r
2207 <dt class="hdlist1">\r
2208 Project-page\r
2209 </dt>\r
2210 <dd>\r
2211 <p>\r
2212     <strong><a href="http://sourceforge.net/projects/zsh/">http://sourceforge.net/projects/zsh/</a></strong>\r
2213 </p>\r
2214 </dd>\r
2215 <dt class="hdlist1">\r
2216 Z shell page at sunsite.dk\r
2217 </dt>\r
2218 <dd>\r
2219 <p>\r
2220     <strong><a href="http://zsh.sunsite.dk/">http://zsh.sunsite.dk/</a></strong>\r
2221 </p>\r
2222 </dd>\r
2223 <dt class="hdlist1">\r
2224 From Bash to Z Shell: Conquering the Command Line - the book\r
2225 </dt>\r
2226 <dd>\r
2227 <p>\r
2228     <strong><a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a></strong>\r
2229 </p>\r
2230 </dd>\r
2231 <dt class="hdlist1">\r
2232 "Zsh - die magische Shell" (german book about Zsh) by Sven Guckes and Julius Plenz\r
2233 </dt>\r
2234 <dd>\r
2235 <p>\r
2236     <strong><a href="http://zshbuch.org/">http://zshbuch.org/</a></strong>\r
2237 </p>\r
2238 </dd>\r
2239 <dt class="hdlist1">\r
2240 Mailinglistarchive\r
2241 </dt>\r
2242 <dd>\r
2243 <p>\r
2244     <strong><a href="http://www.zsh.org/mla/">http://www.zsh.org/mla/</a></strong>\r
2245 </p>\r
2246 </dd>\r
2247 <dt class="hdlist1">\r
2248 ZSH-FAQ\r
2249 </dt>\r
2250 <dd>\r
2251 <p>\r
2252     <strong><a href="http://zsh.dotsrc.org/FAQ/">http://zsh.dotsrc.org/FAQ/</a></strong>\r
2253 </p>\r
2254 </dd>\r
2255 <dt class="hdlist1">\r
2256 Userguide\r
2257 </dt>\r
2258 <dd>\r
2259 <p>\r
2260     <strong><a href="http://zsh.sunsite.dk/Guide/">http://zsh.sunsite.dk/Guide/</a></strong>\r
2261 </p>\r
2262 </dd>\r
2263 <dt class="hdlist1">\r
2264 ZSH-Wiki\r
2265 </dt>\r
2266 <dd>\r
2267 <p>\r
2268     <strong><a href="http://zshwiki.org/home/">http://zshwiki.org/home/</a></strong>\r
2269 </p>\r
2270 </dd>\r
2271 <dt class="hdlist1">\r
2272 A short introduction from BYU\r
2273 </dt>\r
2274 <dd>\r
2275 <p>\r
2276     <strong><a href="http://docs.cs.byu.edu/linux/advanced/zsh.html">http://docs.cs.byu.edu/linux/advanced/zsh.html</a></strong>\r
2277 </p>\r
2278 </dd>\r
2279 <dt class="hdlist1">\r
2280 Mouse-Support ;)\r
2281 </dt>\r
2282 <dd>\r
2283 <p>\r
2284     <strong><a href="http://stchaz.free.fr/mouse.zsh">http://stchaz.free.fr/mouse.zsh</a></strong>\r
2285 </p>\r
2286 </dd>\r
2287 <dt class="hdlist1">\r
2288 Curtains up: introducing the Z shell\r
2289 </dt>\r
2290 <dd>\r
2291 <p>\r
2292     <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
2293 </p>\r
2294 </dd>\r
2295 <dt class="hdlist1">\r
2296 ZSH-Liebhaberseite (german)\r
2297 </dt>\r
2298 <dd>\r
2299 <p>\r
2300     <strong><a href="http://michael-prokop.at/computer/tools_zsh_liebhaber.html">http://michael-prokop.at/computer/tools_zsh_liebhaber.html</a></strong>\r
2301 </p>\r
2302 </dd>\r
2303 <dt class="hdlist1">\r
2304 ZSH-Seite von Michael Prokop (german)\r
2305 </dt>\r
2306 <dd>\r
2307 <p>\r
2308     <strong><a href="http://michael-prokop.at/computer/tools_zsh.html">http://michael-prokop.at/computer/tools_zsh.html</a></strong>\r
2309 </p>\r
2310 </dd>\r
2311 <dt class="hdlist1">\r
2312 ZSH Prompt introduction\r
2313 </dt>\r
2314 <dd>\r
2315 <p>\r
2316     <strong><a href="http://aperiodic.net/phil/prompt/">http://aperiodic.net/phil/prompt/</a></strong>\r
2317 </p>\r
2318 </dd>\r
2319 <dt class="hdlist1">\r
2320 ft&#8217;s zsh configuration\r
2321 </dt>\r
2322 <dd>\r
2323 <p>\r
2324     <strong><a href="http://ft.bewatermyfriend.org/comp/zsh.html">http://ft.bewatermyfriend.org/comp/zsh.html</a></strong>\r
2325 </p>\r
2326 </dd>\r
2327 <dt class="hdlist1">\r
2328 Adam&#8217;s ZSH page\r
2329 </dt>\r
2330 <dd>\r
2331 <p>\r
2332     <strong><a href="http://www.adamspiers.org/computing/zsh/">http://www.adamspiers.org/computing/zsh/</a></strong>\r
2333 </p>\r
2334 </dd>\r
2335 <dt class="hdlist1">\r
2336 Zzappers Best of ZSH Tips\r
2337 </dt>\r
2338 <dd>\r
2339 <p>\r
2340     <strong><a href="http://www.rayninfo.co.uk/tips/zshtips.html">http://www.rayninfo.co.uk/tips/zshtips.html</a></strong>\r
2341 </p>\r
2342 </dd>\r
2343 <dt class="hdlist1">\r
2344 Zsh Webpage by Christian Schneider\r
2345 </dt>\r
2346 <dd>\r
2347 <p>\r
2348     <strong><a href="http://www.strcat.de/zsh/">http://www.strcat.de/zsh/</a></strong>\r
2349 </p>\r
2350 </dd>\r
2351 <dt class="hdlist1">\r
2352 The zsh-lovers webpage\r
2353 </dt>\r
2354 <dd>\r
2355 <p>\r
2356     <strong><a href="http://grml.org/zsh/">http://grml.org/zsh/</a></strong>\r
2357 </p>\r
2358 </dd>\r
2359 <dt class="hdlist1">\r
2360 IRC channel\r
2361 </dt>\r
2362 <dd>\r
2363 <p>\r
2364     <strong>#zsh at irc.libera.chat</strong>\r
2365 </p>\r
2366 </dd>\r
2367 <dt class="hdlist1">\r
2368 The Z shell reference-card (included in the zsh-lovers debian-package)\r
2369 </dt>\r
2370 <dd>\r
2371 <p>\r
2372     <strong><a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a></strong>\r
2373 </p>\r
2374 </dd>\r
2375 </dl></div>\r
2376 </div>\r
2377 </div>\r
2378 <div class="sect1">\r
2379 <h2 id="_authors">AUTHORS</h2>\r
2380 <div class="sectionbody">\r
2381 <div class="paragraph"><p>This manpage was written by Michael Prokop, Christian <em>strcat</em>\r
2382 Schneider and Matthias Kopfermann. But many ideas have been taken from\r
2383 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),\r
2384 google, newsgroups and the zsh-Wiki.<br />\r
2385 Thanks for your cool and incredible tips. We learned much from you!</p></div>\r
2386 <div class="paragraph"><p>In alphabetic order:</p></div>\r
2387 <div class="listingblock">\r
2388 <div class="content">\r
2389 <pre><code>Andrew 'zefram' Main  - http://www.fysh.org/~zefram/\r
2390 Barton E. Schaefer    - http://www.well.com/user/barts/\r
2391 Matthias Kopfermann   - http://www.infodrom.north.de/~matthi/\r
2392 Oliver Kiddle         - http://people.freenet.de/opk/\r
2393 Paul Falstad          - http://www.falstad.com/\r
2394 Peter Stephenson      - http://homepage.ntlworld.com/p.w.stephenson/\r
2395 Richard Coleman\r
2396 Stephane Chazelas     - http://stephane.chazelas.free.fr/\r
2397 Sven Guckes           - http://www.guckes.net/\r
2398 Sven Wischnowsky      - http://w9y.de/zsh/zshrc</code></pre>\r
2399 </div></div>\r
2400 </div>\r
2401 </div>\r
2402 <div class="sect1">\r
2403 <h2 id="_see_also">SEE ALSO</h2>\r
2404 <div class="sectionbody">\r
2405 <div class="paragraph"><p>Manpages of zsh:</p></div>\r
2406 <div class="listingblock">\r
2407 <div class="content">\r
2408 <pre><code>       zsh          Zsh overview\r
2409        zshall       Tthe Z shell meta-man page\r
2410        zshbuiltins  Zsh built-in commands\r
2411        zshcalsys    zsh calendar system\r
2412        zshcompctl   zsh programmable completion\r
2413        zshcompsys   Zsh completion system\r
2414        zshcompwid   Zsh completion widgets\r
2415        zshcontrib   User contributions to zsh\r
2416        zshexpn      Zsh expansion and substitution\r
2417        zshmisc      Anything not fitting into the other sections\r
2418        zshmodules   Zsh loadable modules\r
2419        zshoptions   Zsh options\r
2420        zshparam     Zsh parameters\r
2421        zshroadmap   Informal introduction to the zsh manual\r
2422        zshtcpsys    Zsh tcp system\r
2423        zshzle       Zsh command line editing\r
2424        zshzftpsys   Zsh built-in FTP client\r
2425        zshall       Meta-man page containing all of the above</code></pre>\r
2426 </div></div>\r
2427 <div class="paragraph"><p>Note: especially <em>man zshcontrib</em> covers very useful topics!<br />\r
2428 Book: <strong>From Bash to Z Shell</strong> by Oliver Kiddle, Jerry Peck and Peter\r
2429 Stephenson. <strong>ISBN: 1590593766</strong>. - <strong><a href="http://www.bash2zsh.com/">bash2zsh.com</a></strong><br />\r
2430 Also take a look at the section <strong>LINKS</strong> in this manpage.</p></div>\r
2431 </div>\r
2432 </div>\r
2433 <div class="sect1">\r
2434 <h2 id="_bugs">BUGS</h2>\r
2435 <div class="sectionbody">\r
2436 <div class="paragraph"><p>Probably. This manpage might be never complete. So please report bugs,\r
2437 feedback and suggestions to &lt;<a href="mailto:zsh-lovers@michael-prokop.at">zsh-lovers@michael-prokop.at</a>&gt;. Thank\r
2438 you!</p></div>\r
2439 </div>\r
2440 </div>\r
2441 <div class="sect1">\r
2442 <h2 id="_copyright">COPYRIGHT</h2>\r
2443 <div class="sectionbody">\r
2444 <div class="paragraph"><p>Copyright  (C) Michael Prokop, Christian Schneider and Matthias\r
2445 Kopfermann.</p></div>\r
2446 </div>\r
2447 </div>\r
2448 </div>\r
2449 <div id="footnotes"><hr /></div>\r
2450 <div id="footer">\r
2451 <div id="footer-text">\r
2452 Last updated 2010-07-28 21:55:37 UTC\r
2453 </div>\r
2454 </div>\r
2455 </body>\r
2456 </html>\r