diff options
author | johannst <johannst@users.noreply.github.com> | 2020-04-13 19:02:58 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2020-04-13 19:02:58 +0000 |
commit | ce1a0eaa58f7ad07c5389996a90c4b02bdf573fc (patch) | |
tree | bc7a8855b0b9adc4b63297c29d95f57eae6f6e11 /print.html | |
parent | 0b8ec70afa871d77b86501015793f155689b1fc3 (diff) | |
download | notes-ce1a0eaa58f7ad07c5389996a90c4b02bdf573fc.tar.gz notes-ce1a0eaa58f7ad07c5389996a90c4b02bdf573fc.zip |
deploy: 43e402ba2320ced7972d33c9442b2745afe230f6
Diffstat (limited to 'print.html')
-rw-r--r-- | print.html | 138 |
1 files changed, 132 insertions, 6 deletions
@@ -83,7 +83,7 @@ <nav id="sidebar" class="sidebar" aria-label="Table of contents"> <div id="sidebar-scrollbox" class="sidebar-scrollbox"> - <ol class="chapter"><li class="expanded "><a href="ld.so.html"><strong aria-hidden="true">1.</strong> ld.so</a></li><li class="expanded "><a href="git.html"><strong aria-hidden="true">2.</strong> git</a></li><li class="expanded "><a href="bash.html"><strong aria-hidden="true">3.</strong> bash</a></li><li class="expanded "><a href="tmux.html"><strong aria-hidden="true">4.</strong> tmux</a></li><li class="expanded "><a href="awk.html"><strong aria-hidden="true">5.</strong> awk</a></li><li class="expanded "><a href="gdb.html"><strong aria-hidden="true">6.</strong> gdb</a></li><li class="expanded "><a href="radare2.html"><strong aria-hidden="true">7.</strong> radare2</a></li><li class="expanded "><a href="emacs.html"><strong aria-hidden="true">8.</strong> emacs</a></li><li class="expanded "><a href="fish.html"><strong aria-hidden="true">9.</strong> fish</a></li><li class="expanded "><a href="strace.html"><strong aria-hidden="true">10.</strong> strace</a></li><li class="expanded "><a href="lsof.html"><strong aria-hidden="true">11.</strong> lsof</a></li><li class="expanded "><a href="pidstat.html"><strong aria-hidden="true">12.</strong> pidstat</a></li><li class="expanded "><a href="time.html"><strong aria-hidden="true">13.</strong> time</a></li><li class="expanded "><a href="pgrep.html"><strong aria-hidden="true">14.</strong> pgrep</a></li><li class="expanded "><a href="pstack.html"><strong aria-hidden="true">15.</strong> pstack</a></li><li class="expanded "><a href="perf.html"><strong aria-hidden="true">16.</strong> perf</a></li><li class="expanded "><a href="oprofile.html"><strong aria-hidden="true">17.</strong> OProfile</a></li><li class="expanded "><a href="od.html"><strong aria-hidden="true">18.</strong> od</a></li><li class="expanded "><a href="xxd.html"><strong aria-hidden="true">19.</strong> xxd</a></li><li class="expanded "><a href="readelf.html"><strong aria-hidden="true">20.</strong> readelf</a></li><li class="expanded "><a href="objdump.html"><strong aria-hidden="true">21.</strong> objdump</a></li><li class="expanded "><a href="nm.html"><strong aria-hidden="true">22.</strong> nm</a></li><li class="expanded "><a href="c++filt.html"><strong aria-hidden="true">23.</strong> c++filt</a></li><li class="expanded "><a href="c++.html"><strong aria-hidden="true">24.</strong> c++</a></li><li class="expanded "><a href="glibc.html"><strong aria-hidden="true">25.</strong> glibc</a></li><li class="expanded "><a href="gcc.html"><strong aria-hidden="true">26.</strong> gcc</a></li></ol> + <ol class="chapter"><li class="expanded "><a href="ld.so.html"><strong aria-hidden="true">1.</strong> ld.so</a></li><li class="expanded "><a href="git.html"><strong aria-hidden="true">2.</strong> git</a></li><li class="expanded "><a href="bash.html"><strong aria-hidden="true">3.</strong> bash</a></li><li class="expanded "><a href="zsh.html"><strong aria-hidden="true">4.</strong> zsh</a></li><li class="expanded "><a href="tmux.html"><strong aria-hidden="true">5.</strong> tmux</a></li><li class="expanded "><a href="awk.html"><strong aria-hidden="true">6.</strong> awk</a></li><li class="expanded "><a href="gdb.html"><strong aria-hidden="true">7.</strong> gdb</a></li><li class="expanded "><a href="radare2.html"><strong aria-hidden="true">8.</strong> radare2</a></li><li class="expanded "><a href="emacs.html"><strong aria-hidden="true">9.</strong> emacs</a></li><li class="expanded "><a href="fish.html"><strong aria-hidden="true">10.</strong> fish</a></li><li class="expanded "><a href="strace.html"><strong aria-hidden="true">11.</strong> strace</a></li><li class="expanded "><a href="lsof.html"><strong aria-hidden="true">12.</strong> lsof</a></li><li class="expanded "><a href="pidstat.html"><strong aria-hidden="true">13.</strong> pidstat</a></li><li class="expanded "><a href="time.html"><strong aria-hidden="true">14.</strong> time</a></li><li class="expanded "><a href="pgrep.html"><strong aria-hidden="true">15.</strong> pgrep</a></li><li class="expanded "><a href="pstack.html"><strong aria-hidden="true">16.</strong> pstack</a></li><li class="expanded "><a href="perf.html"><strong aria-hidden="true">17.</strong> perf</a></li><li class="expanded "><a href="oprofile.html"><strong aria-hidden="true">18.</strong> OProfile</a></li><li class="expanded "><a href="od.html"><strong aria-hidden="true">19.</strong> od</a></li><li class="expanded "><a href="xxd.html"><strong aria-hidden="true">20.</strong> xxd</a></li><li class="expanded "><a href="readelf.html"><strong aria-hidden="true">21.</strong> readelf</a></li><li class="expanded "><a href="objdump.html"><strong aria-hidden="true">22.</strong> objdump</a></li><li class="expanded "><a href="nm.html"><strong aria-hidden="true">23.</strong> nm</a></li><li class="expanded "><a href="c++filt.html"><strong aria-hidden="true">24.</strong> c++filt</a></li><li class="expanded "><a href="c++.html"><strong aria-hidden="true">25.</strong> c++</a></li><li class="expanded "><a href="glibc.html"><strong aria-hidden="true">26.</strong> glibc</a></li><li class="expanded "><a href="gcc.html"><strong aria-hidden="true">27.</strong> gcc</a></li></ol> </div> <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> </nav> @@ -469,19 +469,145 @@ COMP_CWORD # index into COMP_WORDS with current cursor position # out COMPREPLY # array with possible completions </code></pre> -<p><code>compgen</code> builtin is used to generate possible matches for <code>word</code> out of possible <code>option</code>s. -The syntax is as follows:</p> +<p>The <code>compgen</code> builtin is used to generate possible matches by comparing <code>word</code> +against words generated by <code>option</code>.</p> <pre><code class="language-bash">compgen [option] [word] # usefule options: +# -W <list> specify list of possible completions +# -d generate list with dirs +# -f generate list with files +# -u generate list with users +# -e generate list with exported variables -# -W <list> compare against word-list +# compare "f" against words "foo" "foobar" "bar" and generate matches compgen -W "foo foobar bar" "f" -# -d compare against dir names -# -f compare against file names +# compare "hom" against file/dir names and generate matches compgen -d -f "hom" </code></pre> +<h3><a class="header" href="#example" id="example">Example</a></h3> +<p>Skeleton to copy/paste for writing simple completions.</p> +<p>Assume a program <code>foo</code> with the following interface:</p> +<pre><code class="language-bash">foo -c green|red|blue -s low|high -f <file> -h +</code></pre> +<p>The completion handler could be implemented as follows:</p> +<pre><code class="language-bash">function _foo() { + local curr=$2 + local prev=$3 + + local opts="-c -s -f -h" + case $prev in + -c) COMPREPLY=( $(compgen -W "green red blue" -- $curr) );; + -s) COMPREPLY=( $(compgen -W "low high" -- $curr) );; + -f) COMPREPLY=( $(compgen -f -- $curr) );; + *) COMPREPLY=( $(compgen -W "$opts" -- $curr) );; + esac +} + +complete -F _foo foo +</code></pre> +<h1><a class="header" href="#zsh1" id="zsh1">zsh(1)</a></h1> +<h2><a class="header" href="#keybindings" id="keybindings">Keybindings</a></h2> +<p>Change input mode:</p> +<pre><code class="language-zsh">bindkey -v change to vi keymap +bindkey -e change to emacs keymap +</code></pre> +<p>Define key-mappings:</p> +<pre><code class="language-zsh">bindkey list mappings in current keymap +bindkey in-str cmd create mapping for `in-str` to `cmd` +bindkey -r in-str remove binding for `in-str` + +# C-v <key> dump <key> code, which can be used in `in-str` +# zle -l list all functions for keybindings +# man zshzle(1) STANDARD WIDGETS: get description of functions +</code></pre> +<h2><a class="header" href="#completion-1" id="completion-1">Completion</a></h2> +<h3><a class="header" href="#installation" id="installation">Installation</a></h3> +<p>Completion functions are provided via files and need to be placed in a location +covered by <code>$fpath</code>. By convention the completion files are names as <code>_<CMD></code>.</p> +<p>A completion skeleton for the command <code>foo</code>, stored in <code>_foo</code></p> +<pre><code class="language-zsh">#compdef _foo foo + +function _foo() { + ... +} +</code></pre> +<p>Alternatively one can install a completion function explicitly by calling <code>compdef <FUNC> <CMD></code>.</p> +<h3><a class="header" href="#completion-variables" id="completion-variables">Completion Variables</a></h3> +<p>Following variables are available in Completion functions:</p> +<pre><code class="language-zsh">$words # array with command line in words +$#words # number words +$CURRENT # index into $words for cursor position +$words[CURRENT-1] # previous word (relative to cursor position) +</code></pre> +<h3><a class="header" href="#completion-functions" id="completion-functions">Completion Functions</a></h3> +<ul> +<li><code>_describe</code> simple completion, just words + description</li> +<li><code>_arguments</code> sophisticated completion, allow to specify actions</li> +</ul> +<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_describea">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_describe</code></a></a></h4> +<pre><code class="language-zsh">_describe MSG COMP +</code></pre> +<ul> +<li><code>MSG</code> simple string with header message</li> +<li><code>COMP</code> array of completions where each entry is <code>"opt:description"</code></li> +</ul> +<pre><code class="language-zsh">function _foo() { + local -a opts + opts=('bla:desc for bla' 'blu:desc for blu') + _describe 'foo-msg' opts +} +compdef _foo foo + +foo <TAB><TAB> + -- foo-msg -- +bla -- desc for bla +blu -- desc for blu +</code></pre> +<h4><a class="header" href="#completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa" id="completion-with-a-hrefhttpzshsourceforgenetdocreleasecompletion-systemhtmlcompletion-functions_argumentsa">Completion with <a href="http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions"><code>_arguments</code></a></a></h4> +<pre><code class="language-zsh">_arguments SPEC [SPEC...] +</code></pre> +<p>where <code>SPEC</code> can have one of the following forms:</p> +<ul> +<li><code>OPT[DESC]:MSG:ACTION</code></li> +<li><code>N:MSG:ACTION</code></li> +</ul> +<p>Available actions</p> +<pre><code class="language-zsh">(op1 op2) list possible matches +->VAL set $state=VAL and continue, `$state` can be checked later in switch case +FUNC call func to generate matches +{STR} evaluate `STR` to generate matches +</code></pre> +<h3><a class="header" href="#example-1" id="example-1">Example</a></h3> +<p>Skeleton to copy/paste for writing simple completions.</p> +<p>Assume a program <code>foo</code> with the following interface:</p> +<pre><code class="language-zsh">foo -c green|red|blue -s low|high -f <file> -d <dir> -h +</code></pre> +<p>The completion handler could be implemented as follows in a file called <code>_foo</code>:</p> +<pre><code class="language-zsh">#compdef _foo foo + +function _foo_color() { + local colors=() + colors+=('green:green color') + colors+=('red:red color') + colors+=('blue:blue color') + _describe "color" colors +} + +function _foo() { + _arguments \ + "-c[define color]:color:->s_color" \ + "-s[select sound]:color:(low high)" \ + "-f[select file]:file:_files" \ + "-d[select dir]:fir:_files -/" \ + "-h[help]" + + case $state in + s_color) _foo_color;; + esac +} +</code></pre> <h1><a class="header" href="#tmux1" id="tmux1">tmux(1)</a></h1> <p>Terminology:</p> <ul> |