openbsd-webzine/issues/issue-8/50_TIPS.html

21 lines
1.2 KiB
HTML
Raw Permalink Normal View History

2022-03-21 20:36:31 +00:00
<article id="tips">
<div class="puffies" aria-hidden="true">🐡🐡🐡</div>
<h2>Shell tips</h2>
<p>It is easy to add autocompletion to commands in ksh, however they are limited because they have to be evaluated when the shell is starting.</p>
2022-03-22 19:54:50 +00:00
<p>In the following example, we can parse the file <pre>~/.ssh/known_hosts</pre> to get hostnames and use this list to set autocompletion entries for some commands:
2022-03-21 20:36:31 +00:00
<pre>
HOSTS_LIST=$(awk '{split($1,a,","); print a[1]}' ~/.ssh/known_hosts)
set -A complete_ssh -- $HOSTS_LIST
set -A complete_ping -- $HOSTS_LIST
set -A complete_sndioctl_1 -- $(sndioctl | cut -d= -f 1)
</pre></p>
2022-03-22 19:54:50 +00:00
<p>In this other example, we autocomplete differently depending on the parameter position
2022-03-21 20:36:31 +00:00
<pre>set -A complete_rclone_1 -- ncdu ls copy sync
set -A complete_rclone_2 -- $(rclone listremotes)
</pre>
2022-03-22 19:54:50 +00:00
Adding autocompletion entries is easy but in ksh it is evaluated at runtime, so you should avoid time consuming evaluations, and some commands like scp or git can't receive much useful completion.</p>
<p>More information can be found about this feature <a class="permalink" href="https://man.openbsd.org/ksh#Emacs_editing_mode">in the ksh man page</a>.</p>
2022-03-21 20:36:31 +00:00
</article>