aboutsummaryrefslogtreecommitdiffhomepage
path: root/bash.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2020-04-13 19:02:58 +0000
committerjohannst <johannst@users.noreply.github.com>2020-04-13 19:02:58 +0000
commitce1a0eaa58f7ad07c5389996a90c4b02bdf573fc (patch)
treebc7a8855b0b9adc4b63297c29d95f57eae6f6e11 /bash.html
parent0b8ec70afa871d77b86501015793f155689b1fc3 (diff)
downloadnotes-ce1a0eaa58f7ad07c5389996a90c4b02bdf573fc.tar.gz
notes-ce1a0eaa58f7ad07c5389996a90c4b02bdf573fc.zip
deploy: 43e402ba2320ced7972d33c9442b2745afe230f6
Diffstat (limited to 'bash.html')
-rw-r--r--bash.html41
1 files changed, 33 insertions, 8 deletions
diff --git a/bash.html b/bash.html
index 9f47774..87a909f 100644
--- a/bash.html
+++ b/bash.html
@@ -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 &lt;list&gt; 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 &lt;list&gt; compare against word-list
+# compare &quot;f&quot; against words &quot;foo&quot; &quot;foobar&quot; &quot;bar&quot; and generate matches
compgen -W &quot;foo foobar bar&quot; &quot;f&quot;
-# -d compare against dir names
-# -f compare against file names
+# compare &quot;hom&quot; against file/dir names and generate matches
compgen -d -f &quot;hom&quot;
</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 &lt;file&gt; -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=&quot;-c -s -f -h&quot;
+ case $prev in
+ -c) COMPREPLY=( $(compgen -W &quot;green red blue&quot; -- $curr) );;
+ -s) COMPREPLY=( $(compgen -W &quot;low high&quot; -- $curr) );;
+ -f) COMPREPLY=( $(compgen -f -- $curr) );;
+ *) COMPREPLY=( $(compgen -W &quot;$opts&quot; -- $curr) );;
+ esac
+}
+
+complete -F _foo foo
+</code></pre>
</main>
@@ -276,7 +301,7 @@ compgen -d -f &quot;hom&quot;
- <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 &quot;hom&quot;
- <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>