diff options
Diffstat (limited to 'bash.html')
-rw-r--r-- | bash.html | 41 |
1 files changed, 33 insertions, 8 deletions
@@ -81,7 +81,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" class="active"><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" class="active"><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> @@ -251,19 +251,44 @@ 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> </main> @@ -276,7 +301,7 @@ compgen -d -f "hom" - <a rel="next" href="tmux.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> + <a rel="next" href="zsh.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> <i class="fa fa-angle-right"></i> </a> @@ -294,7 +319,7 @@ compgen -d -f "hom" - <a href="tmux.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> + <a href="zsh.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right"> <i class="fa fa-angle-right"></i> </a> |