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">
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; }
19 .done { color: green; }
20 .tag { background-color: #add8e6; font-weight:normal }
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% }
29 border: 1pt solid #AEBDCC;
30 background-color: #F3F5F7;
32 font-family: courier, monospace;
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;
53 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
57 <script type="text/javascript">
58 <!--/*--><![CDATA[/*><!--*/
59 function CodeHighlightOn(elem, id)
61 var target = document.getElementById(id);
63 elem.cacheClassElem = elem.className;
64 elem.cacheClassTarget = target.className;
65 target.className = "code-highlighted";
66 elem.className = "code-highlighted";
69 function CodeHighlightOff(elem, id)
71 var target = document.getElementById(id);
72 if(elem.cacheClassElem)
73 elem.className = elem.cacheClassElem;
74 if(elem.cacheClassTarget)
75 target.className = elem.cacheClassTarget;
84 <h1 class="title">The Zsh Pony</h1>
88 <div id="table-of-contents">
89 <h2>Table of Contents</h2>
90 <div id="text-table-of-contents">
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>
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>
107 <li><a href="#sec-9">9 Globbing / Glob Qualifiers </a></li>
108 <li><a href="#sec-10">10 Keybindings </a>
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 <keys>" 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>
124 <li><a href="#sec-11">11 Loadable modules </a>
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>
130 <li><a href="#sec-12">12 Prompt </a>
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>
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>
139 <li><a href="#sec-12-3">12.3 RPOMPT with a smiley (note: the version in grml-zshrc is more sophisticated -> moving smiley) </a></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>
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>
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>
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>
165 <li><a href="#sec-20">20 Fast directory switching </a>
167 <li><a href="#sec-20-1">20.1 check out "dirstack handling" in grml-zshrc for persistent directory stack feature </a></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>
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">
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.
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">
197 <p>Grab a fully featured Zsh configuration:
201 <pre class="example">% wget -O .zshrc http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
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">
216 <pre class="example">% setopt autocd && /tmp
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">
231 <pre class="example">% setopt append_history share_history histignorealldups
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">
246 <pre class="example">% setopt $OPTION
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">
262 <pre class="example">% autoload -U zmv
264 % zmv '* *' '$f:gs/ /_'
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">
279 <pre class="example">% autoload run-help
280 % echo foo | xargs <esc-h>
284 % git commit<esc-h>
286 or even ('g' being an alias for git and 'co' and git alias for commit):
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">
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">
310 <pre class="example">% autoload compinit && compinit
313 % dpkg -L <tab>
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">
328 <pre class="example">% zstyle ':completion:*' menu select
334 Layout is :completion:FUNCTION:COMPLETER:COMMAND-OR-MAGIC-CONTEXT:ARGUMENT:TAG
337 Tip: Get completion help running 'ctrl-x h'.
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">
349 <pre class="example">zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
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">
364 <pre class="example">% bindkey -M menuselect "+" accept-and-menu-complete
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">
378 <p>Makes find(1) useless for many jobs.
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
396 The e glob qualifier - e.g. to match all files of which file
397 says that they are JPEGs:
402 <pre class="example">% ls *(e:'file $REPLY | grep -q JPEG':)
408 <li>(#s) or (#e) for what ^ and $ are in regexps (beginning of line/end of line)
410 <li>(#b) or (#m) to enable backreferences
412 <li>(#i) to match case insensitive
414 <li>(#a) to match approximately (certain errors are ignored, e.g. "(#a1)foo*" matches the string "ofobar")
420 Tip: run e.g. `ls *(<tab>` to get help regarding globbing.
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">
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">
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">
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.
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 <keys>" to find out which action is bount to a key </h3>
460 <div class="outline-text-3" id="text-10-3">
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">
470 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
472 <colgroup><col class="left" /><col class="left" />
475 <tr><th scope="col" class="left">Keybinding</th><th scope="col" class="left">Meaning</th></tr>
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>
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">
507 <pre class="example">% slash-backward-kill-word() {
508 local WORDCHARS="${WORDCHARS:s@/@}"
509 zle backward-kill-word
511 % zle -N slash-backward-kill-word
512 % bindkey '\e^?' slash-backward-kill-word
513 % cd /usr/share/doc/mutt/examples/<alt+backspace>
515 Note: configured by default in grml-zshrc, so ready for usage out-of-the-box.
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">
530 <pre class="example">% echo 123
534 % echo <cursor-up|down>
536 % echo 2<page-up|down>
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">
551 <pre class="example">% <ctrl-r>scp*r
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">
564 <li>It's what readline is for bash (move, delete, copy words/lines/…)
566 <li>Basic layout of custom widgets, used like functions:
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
580 <li>ctrl-x-z provides help<sub>zle</sub><sub>parse</sub><sub>keybindings</sub> in grml-zshrc
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">
595 <pre class="example">% autoload edit-command-line && zle -N edit-command-line
596 % bindkey '\ee' edit-command-line
597 % $SOME_COMMAND_LINE <esc-e>
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">
612 <pre class="example">insert-datestamp() { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; }
613 zle -N insert-datestamp
614 bindkey '^Ed' insert-datestamp
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">
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 <esc-m>
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">
647 <pre class="example">% zle -C hist-complete complete-word _generic
648 % zstyle ':completion:hist-complete:*' completer _history
649 % bindkey "^X^X" hist-complete
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">
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">
672 <pre class="example">% autoload -U tetris
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">
688 <pre class="example">% autoload -U url-quote-magic
689 % zle -N self-insert url-quote-magic
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>
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">
707 <pre class="example">% autoload -U promptinit
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">
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">
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">
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">
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 -> moving smiley) </h3>
751 <div class="outline-text-3" id="text-12-3">
756 <pre class="example">precmd () { RPROMPT="%(?..:()%" }
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">
772 <pre class="example">autoload -Uz vcs_info
776 [[ -n $vcs_info_msg_0_ ]] && psvar[1]="$vcs_info_msg_0_"
778 PS1="%m%(1v.%F{green}%1v%f.)%# "
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">
793 <pre class="example">% hash -d doc=/usr/share/doc
795 % hash -d deb=/var/cache/apt/archives
796 % sudo dpkg -i ~deb/foobar*deb
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">
811 <pre class="example">% vared PATH
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">
823 <p>Supports csh style bang history expansion.
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'.
843 …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$' )
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">
854 <li>fc -p/fc -a/fc -P deals with the "history stack"
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
859 <li>You can use that to "bind" certain histories to specific directories.
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">
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">
882 <pre class="example">% print -l -- ${(o)history%% *} | uniq -c | sort -nr | head -n 10
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">
898 <pre class="example">% mkdir -p /tmp/linux-2.6.3{8,9}/demo
899 % cd /tmp/linux-2.6.38/demo
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">
921 <pre class="example">% alias -s txt=vim
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">
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">
946 <pre class="example">% dchange $DEBIAN_PACKAGE
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">
961 <pre class="example">% cp file /tmp/doesnotexist/<ctrl-xM>
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">
976 <pre class="example">% cdt
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">
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'!
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">
1001 <pre class="example">% which cd
1005 [[ ! -e ${1:h} ]] && return 1
1006 print "Correcting ${1} to ${1:h}"
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">
1027 <pre class="example">% vim # ... <ctrl-z>
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">
1044 <pre class="example">% which sudo-command-line
1045 sudo-command-line () {
1046 [[ -z $BUFFER ]] && zle up-history
1047 if [[ $BUFFER != sudo\ * ]]
1049 BUFFER="sudo $BUFFER"
1050 CURSOR=$(( CURSOR+5 ))
1053 % gparted /dev/sda <ctrl-o s>
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">
1069 <pre class="example">% cd -<tab>
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">
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">
1089 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
1091 <colgroup><col class="left" /><col class="left" />
1094 <tr><th scope="col" class="left">Long version</th><th scope="col" class="left">Short version</th></tr>
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 <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<tab></td></tr>
1101 <tr><td class="left">gzip -cd foo.gz && less foo</td><td class="left">less <(gzip -cd foo.gz)</td></tr>
1102 <tr><td class="left">ls >file1; ls >file2; ls >file3</td><td class="left">ls >file1 >file2 >file3</td></tr>
1103 <tr><td class="left">-</td><td class="left">less <file1 <file2</td></tr>
1104 <tr><td class="left">-</td><td class="left">diff <(sort foo) <(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>
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">
1118 <li>Q: How to I get a listing of all my currently in use options?
1125 <pre class="example"> setopt ksh_option_print && setopt
1129 printf '%s=%s\n' "${(@kv)options}"
1134 <li>Q: Why do I get "zsh: command not found:" even though I just installed the program?
1141 <pre class="example">% rehash
1146 or use completion system as provided by grml-zshrc (completion will rehash automatically).
1148 <li>Q: What's this strange word splitting thing?
1151 Answer: see <a href="http://zsh.sourceforge.net/FAQ/zshfaq03.html">http://zsh.sourceforge.net/FAQ/zshfaq03.html</a>
1155 <pre class="example">% var="foo bar"
1156 % args() { echo $#; }
1159 % setopt shwordsplit
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">
1177 <li>Zsh Homepage: <a href="http://zsh.sourceforge.net/">http://zsh.sourceforge.net/</a>
1179 <li>Zsh Wiki: <a href="http://zshwiki.org">http://zshwiki.org</a>
1181 <li>Zsh Manpages: man zshall
1183 <li>Zsh Reference Card: <a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a>
1185 <li>User's Guide to ZSH: <a href="http://zsh.sourceforge.net/Guide/">http://zsh.sourceforge.net/Guide/</a> (old but still interesting)
1187 <li>Zsh Talk by caphuso: <a href="http://ft.bewatermyfriend.org/comp/zshtalk.html">http://ft.bewatermyfriend.org/comp/zshtalk.html</a>
1189 <li>English Book: <a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a>
1191 <li>German Book: <a href="http://zshbuch.org/">http://zshbuch.org/</a>
1193 <li>Grml's Zsh stuff: <a href="http://grml.org/zsh/">http://grml.org/zsh/</a>
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">
1208 Thanks to Frank Terbeck for reviewing and his valuable feedback (which isn't limited to this document :)).
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">
1218 <p>(c) 2011 by Michael Prokop <mika@grml.org>
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
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>