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