Clarify that we no longer support i586 but require i686+
[grml.org.git] / zsh-pony / index.html
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"
5 lang="en" xml:lang="en">
6 <head>
7 <title>The Zsh Pony</title>
8 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
9 <meta name="generator" content="Org-mode"/>
10 <meta name="generated" content="2011-07-29 21:33:35 CEST"/>
11 <meta name="author" content=""/>
12 <meta name="description" content=""/>
13 <meta name="keywords" content=""/>
14 <style type="text/css">
15  <!--/*--><![CDATA[/*><!--*/
16   html { font-family: Times, serif; font-size: 12pt; }
17   .title  { text-align: center; }
18   .todo   { color: red; }
19   .done   { color: green; }
20   .tag    { background-color: #add8e6; font-weight:normal }
21   .target { }
22   .timestamp { color: #bebebe; }
23   .timestamp-kwd { color: #5f9ea0; }
24   .right  {margin-left:auto; margin-right:0px;  text-align:right;}
25   .left   {margin-left:0px;  margin-right:auto; text-align:left;}
26   .center {margin-left:auto; margin-right:auto; text-align:center;}
27   p.verse { margin-left: 3% }
28   pre {
29         border: 1pt solid #AEBDCC;
30         background-color: #F3F5F7;
31         padding: 5pt;
32         font-family: courier, monospace;
33         font-size: 90%;
34         overflow:auto;
35   }
36   table { border-collapse: collapse; }
37   td, th { vertical-align: top;  }
38   th.right  { text-align:center;  }
39   th.left   { text-align:center;   }
40   th.center { text-align:center; }
41   td.right  { text-align:right;  }
42   td.left   { text-align:left;   }
43   td.center { text-align:center; }
44   dt { font-weight: bold; }
45   div.figure { padding: 0.5em; }
46   div.figure p { text-align: center; }
47   textarea { overflow-x: auto; }
48   .linenr { font-size:smaller }
49   .code-highlighted {background-color:#ffff00;}
50   .org-info-js_info-navigation { border-style:none; }
51   #org-info-js_console-label { font-size:10px; font-weight:bold;
52                                white-space:nowrap; }
53   .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
54                                  font-weight:bold; }
55   /*]]>*/-->
56 </style>
57 <script type="text/javascript">
58 <!--/*--><![CDATA[/*><!--*/
59  function CodeHighlightOn(elem, id)
60  {
61    var target = document.getElementById(id);
62    if(null != target) {
63      elem.cacheClassElem = elem.className;
64      elem.cacheClassTarget = target.className;
65      target.className = "code-highlighted";
66      elem.className   = "code-highlighted";
67    }
68  }
69  function CodeHighlightOff(elem, id)
70  {
71    var target = document.getElementById(id);
72    if(elem.cacheClassElem)
73      elem.className = elem.cacheClassElem;
74    if(elem.cacheClassTarget)
75      target.className = elem.cacheClassTarget;
76  }
77 /*]]>*///-->
78 </script>
79
80 </head>
81 <body>
82 <div id="content">
83
84 <h1 class="title">The Zsh Pony</h1>
85 <p>============
86 </p>
87
88 <div id="table-of-contents">
89 <h2>Table of Contents</h2>
90 <div id="text-table-of-contents">
91 <ul>
92 <li><a href="#sec-1">1 Preface </a></li>
93 <li><a href="#sec-2">2 Grml-zshrc </a></li>
94 <li><a href="#sec-3">3 Switching directories for lazy people </a></li>
95 <li><a href="#sec-4">4 Share history file amongst all Zsh sessions, ignoring dupes </a></li>
96 <li><a href="#sec-5">5 Option Setting in Zsh, AKA setopt* </a></li>
97 <li><a href="#sec-6">6 Replace spaces in filenames with a underline </a></li>
98 <li><a href="#sec-7">7 Fast Manpage access </a></li>
99 <li><a href="#sec-8">8 Completion System </a>
100 <ul>
101 <li><a href="#sec-8-1">8.1 Enable completion </a></li>
102 <li><a href="#sec-8-2">8.2 Menu Selection </a></li>
103 <li><a href="#sec-8-3">8.3 Use colors in completion </a></li>
104 <li><a href="#sec-8-4">8.4 Pick item but stay in the menu </a></li>
105 </ul>
106 </li>
107 <li><a href="#sec-9">9 Globbing / Glob Qualifiers </a></li>
108 <li><a href="#sec-10">10 Keybindings </a>
109 <ul>
110 <li><a href="#sec-10-1">10.1 Run `bindkey` to get a listing of currently active keybindings </a></li>
111 <li><a href="#sec-10-2">10.2 Get emacs-like keybindings </a></li>
112 <li><a href="#sec-10-3">10.3 Tip: run "bindkey ctrl-v &lt;keys&gt;" to find out which action is bount to a key </a></li>
113 <li><a href="#sec-10-4">10.4 Some interesting keybindings </a></li>
114 <li><a href="#sec-10-5">10.5 Remove last part from directory name </a></li>
115 <li><a href="#sec-10-6">10.6 Keybindings {up,down}-line-or-search and history-beginning-search-{backward,forward}-end </a></li>
116 <li><a href="#sec-10-7">10.7 Incremental search with history-incremental-pattern-search-backward: </a></li>
117 <li><a href="#sec-10-8">10.8 Zsh Line Editor (AKA zle) </a></li>
118 <li><a href="#sec-10-9">10.9 Edit command line in editor </a></li>
119 <li><a href="#sec-10-10">10.10 Insert a timestamp on the command line (yyyy-mm-dd) </a></li>
120 <li><a href="#sec-10-11">10.11 Insert last typed word </a></li>
121 <li><a href="#sec-10-12">10.12 Complete word from history with menu </a></li>
122 </ul>
123 </li>
124 <li><a href="#sec-11">11 Loadable modules </a>
125 <ul>
126 <li><a href="#sec-11-1">11.1 Play tetris </a></li>
127 <li><a href="#sec-11-2">11.2 URL quoting </a></li>
128 </ul>
129 </li>
130 <li><a href="#sec-12">12 Prompt </a>
131 <ul>
132 <li><a href="#sec-12-1">12.1 Exit code in prompt, if it's not exit code 0 </a></li>
133 <li><a href="#sec-12-2">12.2 Special functions </a>
134 <ul>
135 <li><a href="#sec-12-2-1">12.2.1 precmd(): executed before each prompt - e.g. for setting prompt information </a></li>
136 <li><a href="#sec-12-2-2">12.2.2 preexec(): running before every command - e.g. for setting GNU screen title </a></li>
137 </ul>
138 </li>
139 <li><a href="#sec-12-3">12.3 RPOMPT with a smiley (note: the version in grml-zshrc is more sophisticated -&gt; moving smiley) </a></li>
140 </ul>
141 </li>
142 <li><a href="#sec-13">13 Get VCS information into your prompt - vcs_info </a></li>
143 <li><a href="#sec-14">14 Hashed directories </a></li>
144 <li><a href="#sec-15">15 On-the-fly editing of variables </a></li>
145 <li><a href="#sec-16">16 History </a>
146 <ul>
147 <li><a href="#sec-16-1">16.1 fc </a></li>
148 <li><a href="#sec-16-2">16.2 Top 10 commands </a></li>
149 <li><a href="#sec-16-3">16.3 Check your history for most frequently used commands and create aliases/functions for them (AKA top10): </a></li>
150 </ul>
151 </li>
152 <li><a href="#sec-17">17 Text replacing </a></li>
153 <li><a href="#sec-18">18 Suffix aliases </a></li>
154 <li><a href="#sec-19">19 Grml-zshrc specific stuff </a>
155 <ul>
156 <li><a href="#sec-19-1">19.1 List changelog of a Debian package </a></li>
157 <li><a href="#sec-19-2">19.2 In-place mkdir to create directory under cursor or the selected area </a></li>
158 <li><a href="#sec-19-3">19.3 Create a temporary directory and change cwd to it </a></li>
159 <li><a href="#sec-19-4">19.4 Directory specific shell configuration with Zsh </a></li>
160 <li><a href="#sec-19-5">19.5 Smart cd </a></li>
161 <li><a href="#sec-19-6">19.6 grml-zsh-fg </a></li>
162 <li><a href="#sec-19-7">19.7 sudo-command-line </a></li>
163 </ul>
164 </li>
165 <li><a href="#sec-20">20 Fast directory switching </a>
166 <ul>
167 <li><a href="#sec-20-1">20.1 check out "dirstack handling" in grml-zshrc for persistent directory stack feature </a></li>
168 </ul>
169 </li>
170 <li><a href="#sec-21">21 Speed up typing </a></li>
171 <li><a href="#sec-22">22 FAQ </a></li>
172 <li><a href="#sec-23">23 Important Resources </a></li>
173 <li><a href="#sec-24">24 Credits </a></li>
174 <li><a href="#sec-25">25 Copyright </a></li>
175 </ul>
176 </div>
177 </div>
178
179 <div id="outline-container-1" class="outline-2">
180 <h2 id="sec-1"><span class="section-number-2">1</span> Preface </h2>
181 <div class="outline-text-2" id="text-1">
182
183
184 <p>
185   The Zsh defaults to a minimalistic configuration which doesn't show the
186   potential behind this powerful and flexible shell. The Zsh pony project
187   provides a list of really hot stuff of what's possible with Zsh.
188 </p>
189 </div>
190
191 </div>
192
193 <div id="outline-container-2" class="outline-2">
194 <h2 id="sec-2"><span class="section-number-2">2</span> Grml-zshrc </h2>
195 <div class="outline-text-2" id="text-2">
196
197 <p>Grab a fully featured Zsh configuration:
198 </p>
199
200
201 <pre class="example">% wget -O .zshrc        http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
202 </pre>
203
204
205 </div>
206
207 </div>
208
209 <div id="outline-container-3" class="outline-2">
210 <h2 id="sec-3"><span class="section-number-2">3</span> Switching directories for lazy people </h2>
211 <div class="outline-text-2" id="text-3">
212
213
214
215
216 <pre class="example">% setopt autocd &amp;&amp; /tmp
217 </pre>
218
219
220 </div>
221
222 </div>
223
224 <div id="outline-container-4" class="outline-2">
225 <h2 id="sec-4"><span class="section-number-2">4</span> Share history file amongst all Zsh sessions, ignoring dupes </h2>
226 <div class="outline-text-2" id="text-4">
227
228
229
230
231 <pre class="example">% setopt append_history share_history histignorealldups
232 </pre>
233
234
235 </div>
236
237 </div>
238
239 <div id="outline-container-5" class="outline-2">
240 <h2 id="sec-5"><span class="section-number-2">5</span> Option Setting in Zsh, AKA setopt* </h2>
241 <div class="outline-text-2" id="text-5">
242
243
244
245
246 <pre class="example">% setopt $OPTION
247 % man zshoptions
248 </pre>
249
250
251 </div>
252
253 </div>
254
255 <div id="outline-container-6" class="outline-2">
256 <h2 id="sec-6"><span class="section-number-2">6</span> Replace spaces in filenames with a underline </h2>
257 <div class="outline-text-2" id="text-6">
258
259
260
261
262 <pre class="example">% autoload -U zmv
263 % touch 1\ 2  3\ 4\ 5
264 % zmv '* *' '$f:gs/ /_'
265 </pre>
266
267
268 </div>
269
270 </div>
271
272 <div id="outline-container-7" class="outline-2">
273 <h2 id="sec-7"><span class="section-number-2">7</span> Fast Manpage access </h2>
274 <div class="outline-text-2" id="text-7">
275
276
277
278
279 <pre class="example">% autoload run-help
280 % echo foo | xargs &lt;esc-h&gt;
281
282 and then:
283
284 % git commit&lt;esc-h&gt;
285
286 or even ('g' being an alias for git and 'co' and git alias for commit):
287
288 % g co&lt;esc-h&gt;
289 </pre>
290
291
292 </div>
293
294 </div>
295
296 <div id="outline-container-8" class="outline-2">
297 <h2 id="sec-8"><span class="section-number-2">8</span> Completion System </h2>
298 <div class="outline-text-2" id="text-8">
299
300
301 </div>
302
303 <div id="outline-container-8-1" class="outline-3">
304 <h3 id="sec-8-1"><span class="section-number-3">8.1</span> Enable completion </h3>
305 <div class="outline-text-3" id="text-8-1">
306
307
308
309
310 <pre class="example">% autoload compinit &amp;&amp; compinit
311 % kill c&lt;tab&gt;
312 % man z&lt;tab&gt;
313 % dpkg -L &lt;tab&gt;
314 </pre>
315
316
317 </div>
318
319 </div>
320
321 <div id="outline-container-8-2" class="outline-3">
322 <h3 id="sec-8-2"><span class="section-number-3">8.2</span> Menu Selection </h3>
323 <div class="outline-text-3" id="text-8-2">
324
325
326
327
328 <pre class="example">% zstyle ':completion:*' menu select
329 </pre>
330
331
332
333 <p>
334 Layout is :completion:FUNCTION:COMPLETER:COMMAND-OR-MAGIC-CONTEXT:ARGUMENT:TAG
335 </p>
336 <p>
337 Tip: Get completion help running 'ctrl-x h'.
338 </p></div>
339
340 </div>
341
342 <div id="outline-container-8-3" class="outline-3">
343 <h3 id="sec-8-3"><span class="section-number-3">8.3</span> Use colors in completion </h3>
344 <div class="outline-text-3" id="text-8-3">
345
346
347
348
349 <pre class="example">zstyle ':completion:*:default'         list-colors ${(s.:.)LS_COLORS}
350 </pre>
351
352
353 </div>
354
355 </div>
356
357 <div id="outline-container-8-4" class="outline-3">
358 <h3 id="sec-8-4"><span class="section-number-3">8.4</span> Pick item but stay in the menu </h3>
359 <div class="outline-text-3" id="text-8-4">
360
361
362
363
364 <pre class="example">% bindkey -M menuselect "+" accept-and-menu-complete
365 % ls &lt;tab&gt; +
366 </pre>
367
368
369 </div>
370 </div>
371
372 </div>
373
374 <div id="outline-container-9" class="outline-2">
375 <h2 id="sec-9"><span class="section-number-2">9</span> Globbing / Glob Qualifiers </h2>
376 <div class="outline-text-2" id="text-9">
377
378 <p>Makes find(1) useless for many jobs.
379 </p>
380
381
382 <pre class="example">% setopt extendedglob
383 % rm ../debianpackage(.)   # remove files only
384 % ls -d *(/)               # list directories only
385 % ls /etc/*(@)             # list symlinks only
386 % ls -l *.(png|jpg|gif)    # list pictures only
387 % ls *(*)                  # list executables only
388 % ls /etc/**/zsh           # which directories contain 'zsh'?
389 % ls **/*(-@)              # list dangling symlinks ('**' recurses down directory trees)
390 % ls foo*~*bar*            # match everything that starts with foo but doesn't contain bar
391 </pre>
392
393
394
395 <p>
396 The e glob qualifier -  e.g. to match all files of which file
397 says that they are JPEGs:
398 </p>
399
400
401
402 <pre class="example">% ls *(e:'file $REPLY | grep -q JPEG':)
403 </pre>
404
405
406
407 <ul>
408 <li>(#s) or (#e) for what ^ and $ are in regexps (beginning of line/end of line)
409 </li>
410 <li>(#b) or (#m) to enable backreferences
411 </li>
412 <li>(#i) to match case insensitive
413 </li>
414 <li>(#a) to match approximately (certain errors are ignored, e.g. "(#a1)foo*" matches the string "ofobar")
415 </li>
416 </ul>
417
418
419 <p>
420 Tip: run e.g. `ls *(&lt;tab&gt;` to get help regarding globbing.
421 </p></div>
422
423 </div>
424
425 <div id="outline-container-10" class="outline-2">
426 <h2 id="sec-10"><span class="section-number-2">10</span> Keybindings </h2>
427 <div class="outline-text-2" id="text-10">
428
429
430 </div>
431
432 <div id="outline-container-10-1" class="outline-3">
433 <h3 id="sec-10-1"><span class="section-number-3">10.1</span> Run `bindkey` to get a listing of currently active keybindings </h3>
434 <div class="outline-text-3" id="text-10-1">
435
436 <p>Notes:
437 </p><ol>
438 <li>^ := ctrl
439 </li>
440 <li>^[ := esc
441 </li>
442 </ol>
443
444 </div>
445
446 </div>
447
448 <div id="outline-container-10-2" class="outline-3">
449 <h3 id="sec-10-2"><span class="section-number-3">10.2</span> Get emacs-like keybindings </h3>
450 <div class="outline-text-3" id="text-10-2">
451
452 <p>Zsh defaults to vi keybindings ('bindkey -v') if $VISUAL or $EDITOR contain string 'vi'.
453 Run 'bindkey -e' to get emacs-like keybindings then.
454 </p></div>
455
456 </div>
457
458 <div id="outline-container-10-3" class="outline-3">
459 <h3 id="sec-10-3"><span class="section-number-3">10.3</span> Tip: run "bindkey ctrl-v &lt;keys&gt;" to find out which action is bount to a key </h3>
460 <div class="outline-text-3" id="text-10-3">
461
462 </div>
463
464 </div>
465
466 <div id="outline-container-10-4" class="outline-3">
467 <h3 id="sec-10-4"><span class="section-number-3">10.4</span> Some interesting keybindings </h3>
468 <div class="outline-text-3" id="text-10-4">
469
470 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
471 <caption></caption>
472 <colgroup><col class="left" /><col class="left" />
473 </colgroup>
474 <thead>
475 <tr><th scope="col" class="left">Keybinding</th><th scope="col" class="left">Meaning</th></tr>
476 </thead>
477 <tbody>
478 <tr><td class="left">ctrl-d</td><td class="left">complete + EOF</td></tr>
479 <tr><td class="left">ctrl-l</td><td class="left">clear screen</td></tr>
480 <tr><td class="left">ctrl-w</td><td class="left">delete last word</td></tr>
481 <tr><td class="left">ctrl-_</td><td class="left">undo</td></tr>
482 <tr><td class="left">tab</td><td class="left">complete and take first result</td></tr>
483 <tr><td class="left">esc-.</td><td class="left">insert last parameter of last typed command (similar to typing !$)</td></tr>
484 <tr><td class="left">ctrl-a</td><td class="left">begin of line</td></tr>
485 <tr><td class="left">ctrl-e</td><td class="left">end of line</td></tr>
486 <tr><td class="left">alt-'</td><td class="left">quote-line ('')</td></tr>
487 <tr><td class="left">alt-?</td><td class="left">which-command</td></tr>
488 <tr><td class="left">ctrl-k</td><td class="left">kill line</td></tr>
489 <tr><td class="left">ctrl-u</td><td class="left">kill while line (kill-ring)</td></tr>
490 <tr><td class="left">ctrl-w</td><td class="left">copy last word (kill-ring)</td></tr>
491 <tr><td class="left">ctrl-y</td><td class="left">yank (insert kill-ring)</td></tr>
492 <tr><td class="left">esc-q</td><td class="left">push line</td></tr>
493 </tbody>
494 </table>
495
496 </div>
497
498 </div>
499
500 <div id="outline-container-10-5" class="outline-3">
501 <h3 id="sec-10-5"><span class="section-number-3">10.5</span> Remove last part from directory name </h3>
502 <div class="outline-text-3" id="text-10-5">
503
504
505
506
507 <pre class="example">% slash-backward-kill-word() {
508     local WORDCHARS="${WORDCHARS:s@/@}"
509     zle backward-kill-word
510 }
511 % zle -N slash-backward-kill-word
512 % bindkey '\e^?' slash-backward-kill-word
513 % cd /usr/share/doc/mutt/examples/&lt;alt+backspace&gt;
514
515 Note: configured by default in grml-zshrc, so ready for usage out-of-the-box.
516 </pre>
517
518
519 </div>
520
521 </div>
522
523 <div id="outline-container-10-6" class="outline-3">
524 <h3 id="sec-10-6"><span class="section-number-3">10.6</span> Keybindings {up,down}-line-or-search and history-beginning-search-{backward,forward}-end </h3>
525 <div class="outline-text-3" id="text-10-6">
526
527
528
529
530 <pre class="example">% echo 123
531 % echo 234
532 % ls
533 and then:
534 % echo &lt;cursor-up|down&gt;
535 vs.
536 % echo 2&lt;page-up|down&gt;
537 </pre>
538
539
540 </div>
541
542 </div>
543
544 <div id="outline-container-10-7" class="outline-3">
545 <h3 id="sec-10-7"><span class="section-number-3">10.7</span> Incremental search with history-incremental-pattern-search-backward: </h3>
546 <div class="outline-text-3" id="text-10-7">
547
548
549
550
551 <pre class="example">% &lt;ctrl-r&gt;scp*r
552 </pre>
553
554
555 </div>
556
557 </div>
558
559 <div id="outline-container-10-8" class="outline-3">
560 <h3 id="sec-10-8"><span class="section-number-3">10.8</span> Zsh Line Editor (AKA zle) </h3>
561 <div class="outline-text-3" id="text-10-8">
562
563 <ol>
564 <li>It's what readline is for bash (move, delete, copy words/lines/&hellip;)
565 </li>
566 <li>Basic layout of custom widgets, used like functions:
567 </li>
568 </ol>
569
570
571
572
573 <pre class="example">% foobar() { LBUFFER="foobar $LBUFFER"; } # function
574 % zle -N foobar         # declare function as bindable widget
575 % bindkey '^x^s' foobar # bind command to a keybinding
576 </pre>
577
578
579 <ol>
580 <li>ctrl-x-z provides help<sub>zle</sub><sub>parse</sub><sub>keybindings</sub> in grml-zshrc
581 </li>
582 </ol>
583
584 </div>
585
586 </div>
587
588 <div id="outline-container-10-9" class="outline-3">
589 <h3 id="sec-10-9"><span class="section-number-3">10.9</span> Edit command line in editor </h3>
590 <div class="outline-text-3" id="text-10-9">
591
592
593
594
595 <pre class="example">% autoload edit-command-line &amp;&amp; zle -N edit-command-line
596 % bindkey '\ee' edit-command-line
597 % $SOME_COMMAND_LINE &lt;esc-e&gt;
598 </pre>
599
600
601 </div>
602
603 </div>
604
605 <div id="outline-container-10-10" class="outline-3">
606 <h3 id="sec-10-10"><span class="section-number-3">10.10</span> Insert a timestamp on the command line (yyyy-mm-dd) </h3>
607 <div class="outline-text-3" id="text-10-10">
608
609
610
611
612 <pre class="example">insert-datestamp() { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; }
613 zle -N insert-datestamp
614 bindkey '^Ed' insert-datestamp
615 </pre>
616
617
618 </div>
619
620 </div>
621
622 <div id="outline-container-10-11" class="outline-3">
623 <h3 id="sec-10-11"><span class="section-number-3">10.11</span> Insert last typed word </h3>
624 <div class="outline-text-3" id="text-10-11">
625
626
627
628
629 <pre class="example">% insert-last-typed-word() { zle insert-last-word -- 0 -1 };
630 % zle -N insert-last-typed-word;
631 % bindkey "\em" insert-last-typed-word
632 % mv foobar &lt;esc-m&gt;
633 </pre>
634
635
636 </div>
637
638 </div>
639
640 <div id="outline-container-10-12" class="outline-3">
641 <h3 id="sec-10-12"><span class="section-number-3">10.12</span> Complete word from history with menu </h3>
642 <div class="outline-text-3" id="text-10-12">
643
644
645
646
647 <pre class="example">% zle -C hist-complete complete-word _generic
648 % zstyle ':completion:hist-complete:*' completer _history
649 % bindkey "^X^X" hist-complete
650 </pre>
651
652
653 </div>
654 </div>
655
656 </div>
657
658 <div id="outline-container-11" class="outline-2">
659 <h2 id="sec-11"><span class="section-number-2">11</span> Loadable modules </h2>
660 <div class="outline-text-2" id="text-11">
661
662
663 </div>
664
665 <div id="outline-container-11-1" class="outline-3">
666 <h3 id="sec-11-1"><span class="section-number-3">11.1</span> Play tetris </h3>
667 <div class="outline-text-3" id="text-11-1">
668
669
670
671
672 <pre class="example">% autoload -U tetris
673 % tetris
674 </pre>
675
676
677 </div>
678
679 </div>
680
681 <div id="outline-container-11-2" class="outline-3">
682 <h3 id="sec-11-2"><span class="section-number-3">11.2</span> URL quoting </h3>
683 <div class="outline-text-3" id="text-11-2">
684
685
686
687
688 <pre class="example">% autoload -U url-quote-magic
689 % zle -N self-insert url-quote-magic
690 </pre>
691
692
693 <p>
694 Disclaimer: annoying when using e.g. <a href="http://example.org/foo{1,2,3}.tgz">http://example.org/foo{1,2,3}.tgz</a>
695 </p></div>
696 </div>
697
698 </div>
699
700 <div id="outline-container-12" class="outline-2">
701 <h2 id="sec-12"><span class="section-number-2">12</span> Prompt </h2>
702 <div class="outline-text-2" id="text-12">
703
704
705
706
707 <pre class="example">% autoload -U promptinit
708 % promptinit
709 % prompt fire
710 % prompt &lt;tab&gt;
711 </pre>
712
713
714
715 </div>
716
717 <div id="outline-container-12-1" class="outline-3">
718 <h3 id="sec-12-1"><span class="section-number-3">12.1</span> Exit code in prompt, if it's not exit code 0 </h3>
719 <div class="outline-text-3" id="text-12-1">
720
721 </div>
722
723 </div>
724
725 <div id="outline-container-12-2" class="outline-3">
726 <h3 id="sec-12-2"><span class="section-number-3">12.2</span> Special functions </h3>
727 <div class="outline-text-3" id="text-12-2">
728
729
730 </div>
731
732 <div id="outline-container-12-2-1" class="outline-4">
733 <h4 id="sec-12-2-1"><span class="section-number-4">12.2.1</span> precmd(): executed before each prompt - e.g. for setting prompt information </h4>
734 <div class="outline-text-4" id="text-12-2-1">
735
736 </div>
737
738 </div>
739
740 <div id="outline-container-12-2-2" class="outline-4">
741 <h4 id="sec-12-2-2"><span class="section-number-4">12.2.2</span> preexec(): running before every command - e.g. for setting GNU screen title </h4>
742 <div class="outline-text-4" id="text-12-2-2">
743
744 </div>
745 </div>
746
747 </div>
748
749 <div id="outline-container-12-3" class="outline-3">
750 <h3 id="sec-12-3"><span class="section-number-3">12.3</span> RPOMPT with a smiley (note: the version in grml-zshrc is more sophisticated -&gt; moving smiley) </h3>
751 <div class="outline-text-3" id="text-12-3">
752
753
754
755
756 <pre class="example">precmd () { RPROMPT="%(?..:()%" }
757 </pre>
758
759
760 </div>
761 </div>
762
763 </div>
764
765 <div id="outline-container-13" class="outline-2">
766 <h2 id="sec-13"><span class="section-number-2">13</span> Get VCS information into your prompt - vcs_info </h2>
767 <div class="outline-text-2" id="text-13">
768
769
770
771
772 <pre class="example">autoload -Uz vcs_info
773 precmd() {
774   psvar=()
775   vcs_info
776   [[ -n $vcs_info_msg_0_ ]] &amp;&amp; psvar[1]="$vcs_info_msg_0_"
777 }
778 PS1="%m%(1v.%F{green}%1v%f.)%# "
779 </pre>
780
781
782 </div>
783
784 </div>
785
786 <div id="outline-container-14" class="outline-2">
787 <h2 id="sec-14"><span class="section-number-2">14</span> Hashed directories </h2>
788 <div class="outline-text-2" id="text-14">
789
790
791
792
793 <pre class="example">% hash -d doc=/usr/share/doc
794 % cd ~doc
795 % hash -d deb=/var/cache/apt/archives
796 % sudo dpkg -i ~deb/foobar*deb
797 </pre>
798
799
800 </div>
801
802 </div>
803
804 <div id="outline-container-15" class="outline-2">
805 <h2 id="sec-15"><span class="section-number-2">15</span> On-the-fly editing of variables </h2>
806 <div class="outline-text-2" id="text-15">
807
808
809
810
811 <pre class="example">% vared PATH
812 </pre>
813
814
815 </div>
816
817 </div>
818
819 <div id="outline-container-16" class="outline-2">
820 <h2 id="sec-16"><span class="section-number-2">16</span> History </h2>
821 <div class="outline-text-2" id="text-16">
822
823 <p>Supports csh style bang history expansion.
824 </p>
825
826
827 <pre class="example">% history  # last 16 events
828 % history -E 0  # all history events including date/time information
829 % !23      # Re-execute history command 23
830 % !!       # The last command.
831 % !$       # Last word of the last command.
832 % !-2      # The last but one command.
833 % !-2$     # The last word of the command before the last command.
834 % !#$      # The last word of the current command line.
835 % !#0      # The first word of the current command line.
836 % !?foo    # The last command that matches the pattern `foo'.
837 % !?foo?1  # The second word of the last command line that matches `foo'.
838 </pre>
839
840
841
842 <p>
843 &hellip;and that's really just the start. History expansion is extremely versatile
844 and powerful - but also a bit cryptic for the untrained eye. Practice, young
845 padawan, makes perfect. .o( man zshexpn | less -p '^HISTO.*ANSION$' )
846 </p>
847 </div>
848
849 <div id="outline-container-16-1" class="outline-3">
850 <h3 id="sec-16-1"><span class="section-number-3">16.1</span> fc </h3>
851 <div class="outline-text-3" id="text-16-1">
852
853 <ul>
854 <li>fc -p/fc -a/fc -P deals with the "history stack"
855 </li>
856 <li>"fc -p" clears out the current history and starts with a new one,
857   until you run fc -P, which will restore the old history again
858 </li>
859 <li>You can use that to "bind" certain histories to specific directories.
860 </li>
861 </ul>
862
863 </div>
864
865 </div>
866
867 <div id="outline-container-16-2" class="outline-3">
868 <h3 id="sec-16-2"><span class="section-number-3">16.2</span> Top 10 commands </h3>
869 <div class="outline-text-3" id="text-16-2">
870
871 </div>
872
873 </div>
874
875 <div id="outline-container-16-3" class="outline-3">
876 <h3 id="sec-16-3"><span class="section-number-3">16.3</span> Check your history for most frequently used commands and create aliases/functions for them (AKA top10): </h3>
877 <div class="outline-text-3" id="text-16-3">
878
879
880
881
882 <pre class="example">% print -l -- ${(o)history%% *} | uniq -c | sort -nr | head -n 10
883 </pre>
884
885
886 </div>
887 </div>
888
889 </div>
890
891 <div id="outline-container-17" class="outline-2">
892 <h2 id="sec-17"><span class="section-number-2">17</span> Text replacing </h2>
893 <div class="outline-text-2" id="text-17">
894
895
896
897
898 <pre class="example">% mkdir -p /tmp/linux-2.6.3{8,9}/demo
899 % cd /tmp/linux-2.6.38/demo
900 % cd 38 &lt;tab&gt;
901
902 % echo foo
903 % ^foo^bar
904
905 % echo foo_bar
906 % echo !$:s/foo/baz/
907 </pre>
908
909
910 </div>
911
912 </div>
913
914 <div id="outline-container-18" class="outline-2">
915 <h2 id="sec-18"><span class="section-number-2">18</span> Suffix aliases </h2>
916 <div class="outline-text-2" id="text-18">
917
918
919
920
921 <pre class="example">% alias -s txt=vim
922 % foobar.txt
923 % alias -s pdf=xpdf
924 % print.pdf
925 </pre>
926
927
928 </div>
929
930 </div>
931
932 <div id="outline-container-19" class="outline-2">
933 <h2 id="sec-19"><span class="section-number-2">19</span> Grml-zshrc specific stuff </h2>
934 <div class="outline-text-2" id="text-19">
935
936
937 </div>
938
939 <div id="outline-container-19-1" class="outline-3">
940 <h3 id="sec-19-1"><span class="section-number-3">19.1</span> List changelog of a Debian package </h3>
941 <div class="outline-text-3" id="text-19-1">
942
943
944
945
946 <pre class="example">% dchange $DEBIAN_PACKAGE
947 </pre>
948
949
950 </div>
951
952 </div>
953
954 <div id="outline-container-19-2" class="outline-3">
955 <h3 id="sec-19-2"><span class="section-number-3">19.2</span> In-place mkdir to create directory under cursor or the selected area </h3>
956 <div class="outline-text-3" id="text-19-2">
957
958
959
960
961 <pre class="example">% cp file /tmp/doesnotexist/&lt;ctrl-xM&gt;
962 </pre>
963
964
965 </div>
966
967 </div>
968
969 <div id="outline-container-19-3" class="outline-3">
970 <h3 id="sec-19-3"><span class="section-number-3">19.3</span> Create a temporary directory and change cwd to it </h3>
971 <div class="outline-text-3" id="text-19-3">
972
973
974
975
976 <pre class="example">% cdt
977 </pre>
978
979
980 </div>
981
982 </div>
983
984 <div id="outline-container-19-4" class="outline-3">
985 <h3 id="sec-19-4"><span class="section-number-3">19.4</span> Directory specific shell configuration with Zsh </h3>
986 <div class="outline-text-3" id="text-19-4">
987
988 <p>See <a href="http://michael-prokop.at/blog/2009/05/30/directory-specific-shell-configuration-with-zsh/">http://michael-prokop.at/blog/2009/05/30/directory-specific-shell-configuration-with-zsh/</a>
989 Hint: do you remember the fc section? You can combine the directory specific shell configuration with 'fc -p $file'!
990 </p></div>
991
992 </div>
993
994 <div id="outline-container-19-5" class="outline-3">
995 <h3 id="sec-19-5"><span class="section-number-3">19.5</span> Smart cd </h3>
996 <div class="outline-text-3" id="text-19-5">
997
998
999
1000
1001 <pre class="example">% which cd
1002 cd () {
1003         if [[ -f ${1} ]]
1004         then
1005                 [[ ! -e ${1:h} ]] &amp;&amp; return 1
1006                 print "Correcting ${1} to ${1:h}"
1007                 builtin cd ${1:h}
1008         else
1009                 builtin cd ${1}
1010         fi
1011 }
1012 % cd /etc/fstab
1013 </pre>
1014
1015
1016 </div>
1017
1018 </div>
1019
1020 <div id="outline-container-19-6" class="outline-3">
1021 <h3 id="sec-19-6"><span class="section-number-3">19.6</span> grml-zsh-fg </h3>
1022 <div class="outline-text-3" id="text-19-6">
1023
1024
1025
1026
1027 <pre class="example">% vim # ... &lt;ctrl-z&gt;
1028 % echo foobar
1029 % &lt;ctrl-z&gt;
1030 </pre>
1031
1032
1033 </div>
1034
1035 </div>
1036
1037 <div id="outline-container-19-7" class="outline-3">
1038 <h3 id="sec-19-7"><span class="section-number-3">19.7</span> sudo-command-line </h3>
1039 <div class="outline-text-3" id="text-19-7">
1040
1041
1042
1043
1044 <pre class="example">% which sudo-command-line
1045 sudo-command-line () {
1046         [[ -z $BUFFER ]] &amp;&amp; zle up-history
1047         if [[ $BUFFER != sudo\ * ]]
1048         then
1049                 BUFFER="sudo $BUFFER"
1050                 CURSOR=$(( CURSOR+5 ))
1051         fi
1052 }
1053 % gparted /dev/sda &lt;ctrl-o s&gt;
1054 </pre>
1055
1056
1057 </div>
1058 </div>
1059
1060 </div>
1061
1062 <div id="outline-container-20" class="outline-2">
1063 <h2 id="sec-20"><span class="section-number-2">20</span> Fast directory switching </h2>
1064 <div class="outline-text-2" id="text-20">
1065
1066
1067
1068
1069 <pre class="example">% cd -&lt;tab&gt;
1070 </pre>
1071
1072
1073
1074 </div>
1075
1076 <div id="outline-container-20-1" class="outline-3">
1077 <h3 id="sec-20-1"><span class="section-number-3">20.1</span> check out "dirstack handling" in grml-zshrc for persistent directory stack feature </h3>
1078 <div class="outline-text-3" id="text-20-1">
1079
1080 </div>
1081 </div>
1082
1083 </div>
1084
1085 <div id="outline-container-21" class="outline-2">
1086 <h2 id="sec-21"><span class="section-number-2">21</span> Speed up typing </h2>
1087 <div class="outline-text-2" id="text-21">
1088
1089 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
1090 <caption></caption>
1091 <colgroup><col class="left" /><col class="left" />
1092 </colgroup>
1093 <thead>
1094 <tr><th scope="col" class="left">Long version</th><th scope="col" class="left">Short version</th></tr>
1095 </thead>
1096 <tbody>
1097 <tr><td class="left">for i in $(seq 2 9); do echo $i ; done</td><td class="left">for i in {2..9}; echo $i</td></tr>
1098 <tr><td class="left">ls $(which vim)</td><td class="left">ls =vim</td></tr>
1099 <tr><td class="left">cat bar baz $PIPECHAR sort</td><td class="left">sort &lt;b{ar,az}</td></tr>
1100 <tr><td class="left">ls /usr/share/doc/mutt/examples</td><td class="left">ls /u/s/d/m/e&lt;tab&gt;</td></tr>
1101 <tr><td class="left">gzip -cd foo.gz &amp;&amp; less foo</td><td class="left">less &lt;(gzip -cd foo.gz)</td></tr>
1102 <tr><td class="left">ls &gt;file1; ls &gt;file2; ls &gt;file3</td><td class="left">ls &gt;file1 &gt;file2 &gt;file3</td></tr>
1103 <tr><td class="left">-</td><td class="left">less &lt;file1 &lt;file2</td></tr>
1104 <tr><td class="left">-</td><td class="left">diff &lt;(sort foo) &lt;(sort bar)</td></tr>
1105 <tr><td class="left">-</td><td class="left">xpdf =(zcat ~doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)</td></tr>
1106 </tbody>
1107 </table>
1108
1109 </div>
1110
1111 </div>
1112
1113 <div id="outline-container-22" class="outline-2">
1114 <h2 id="sec-22"><span class="section-number-2">22</span> FAQ </h2>
1115 <div class="outline-text-2" id="text-22">
1116
1117 <ol>
1118 <li>Q: How to I get a listing of all my currently in use options?
1119
1120 <p>
1121   Answer:
1122 </p>
1123
1124
1125 <pre class="example">  setopt ksh_option_print &amp;&amp; setopt
1126
1127 or:
1128
1129   printf '%s=%s\n' "${(@kv)options}"
1130 </pre>
1131
1132
1133 </li>
1134 <li>Q: Why do I get "zsh: command not found:" even though I just installed the program?
1135
1136 <p>
1137   Answer: execute:
1138 </p>
1139
1140
1141 <pre class="example">% rehash
1142 </pre>
1143
1144
1145 <p>
1146   or use completion system as provided by grml-zshrc (completion will rehash automatically).
1147 </p></li>
1148 <li>Q: What's this strange word splitting thing?
1149
1150 <p>
1151   Answer: see <a href="http://zsh.sourceforge.net/FAQ/zshfaq03.html">http://zsh.sourceforge.net/FAQ/zshfaq03.html</a>
1152 </p>
1153
1154
1155 <pre class="example">% var="foo bar"
1156 % args() { echo $#; }
1157 % args $var
1158 1
1159 % setopt shwordsplit
1160 % args $var
1161 2
1162 </pre>
1163
1164
1165 </li>
1166 </ol>
1167
1168 </div>
1169
1170 </div>
1171
1172 <div id="outline-container-23" class="outline-2">
1173 <h2 id="sec-23"><span class="section-number-2">23</span> Important Resources </h2>
1174 <div class="outline-text-2" id="text-23">
1175
1176 <ol>
1177 <li>Zsh Homepage: <a href="http://zsh.sourceforge.net/">http://zsh.sourceforge.net/</a>
1178 </li>
1179 <li>Zsh Wiki: <a href="http://zshwiki.org">http://zshwiki.org</a>
1180 </li>
1181 <li>Zsh Manpages: man zshall
1182 </li>
1183 <li>Zsh Reference Card: <a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a>
1184 </li>
1185 <li>User's Guide to ZSH: <a href="http://zsh.sourceforge.net/Guide/">http://zsh.sourceforge.net/Guide/</a> (old but still interesting)
1186 </li>
1187 <li>Zsh Talk by caphuso:  <a href="http://ft.bewatermyfriend.org/comp/zshtalk.html">http://ft.bewatermyfriend.org/comp/zshtalk.html</a>
1188 </li>
1189 <li>English Book: <a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a>
1190 </li>
1191 <li>German Book: <a href="http://zshbuch.org/">http://zshbuch.org/</a>
1192 </li>
1193 <li>Grml's Zsh stuff: <a href="http://grml.org/zsh/">http://grml.org/zsh/</a>
1194 </li>
1195 </ol>
1196
1197
1198 </div>
1199
1200 </div>
1201
1202 <div id="outline-container-24" class="outline-2">
1203 <h2 id="sec-24"><span class="section-number-2">24</span> Credits </h2>
1204 <div class="outline-text-2" id="text-24">
1205
1206
1207 <p>
1208 Thanks to Frank Terbeck for reviewing and his valuable feedback (which isn't limited to this document :)).
1209 </p>
1210 </div>
1211
1212 </div>
1213
1214 <div id="outline-container-25" class="outline-2">
1215 <h2 id="sec-25"><span class="section-number-2">25</span> Copyright </h2>
1216 <div class="outline-text-2" id="text-25">
1217
1218 <p>(c) 2011 by Michael Prokop &lt;mika@grml.org&gt;
1219 </p>
1220 <div id="footnotes">
1221 <h2 class="footnotes">Footnotes: </h2>
1222 <div id="text-footnotes">
1223 <p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup> DEFINITION NOT FOUND: 1
1224 </p>
1225 </div>
1226 </div>
1227
1228 </div>
1229 </div>
1230 <div id="postamble">
1231 <p class="date">Date: 2011-07-29 21:33:35 CEST</p>
1232 <p class="author">Author: </p>
1233 <p class="creator">Org version 7.6 with Emacs version 23</p>
1234 <a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
1235 </div>
1236 </div>
1237 </body>
1238 </html>