mirror of
https://github.com/arcan1s/arcanis.me.git
synced 2025-07-23 01:19:55 +00:00
change name= to id= in <a> tags
This commit is contained in:
@ -8,10 +8,10 @@ title: Writting own Shell completions. Bash
|
||||
short: writting-own-completions-p2
|
||||
description: <figure class="img"><img src="/resources/papers/bash_completion.png" alt="bash_completion"></figure> Some basics of creating a completion files for own application are described in these articles.
|
||||
---
|
||||
<h2><a href="#preamble" class="anchor" name="preamble"><span class="octicon octicon-link"></span></a>Preamble</h2>
|
||||
<h2><a href="#preamble" class="anchor" id="preamble"><span class="octicon octicon-link"></span></a>Preamble</h2>
|
||||
<p>While developing <a href="/ru/projects/netctl-gui" title="Netctl-gui project page">one of my projects</a> I have wanted to add completion files. I have already tried to create these files, but I was too lazy to read some manuals about it.</p>
|
||||
|
||||
<h2><a href="#introduction" class="anchor" name="introduction"><span class="octicon octicon-link"></span></a>Introduction</h2>
|
||||
<h2><a href="#introduction" class="anchor" id="introduction"><span class="octicon octicon-link"></span></a>Introduction</h2>
|
||||
<p>Bash, <a href="/ru/2014/07/17/writting-own-completions-p1" title="Zsh completions paper">unlike zsh</a>, demands some dirty workarounds for completions. Cursory have Googled, I have not found a more or less normal tutorials, so it is based on the available <code>pacman</code> completion files in my system.</p>
|
||||
|
||||
<p>Lets consider the example of the same my application. I remind you that a part of help message is as follows:</p>
|
||||
@ -32,7 +32,7 @@ netctl-gui [ -h | --help ] [ -e ESSID | --essid ESSID ] [ -с FILE | --config FI
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h2><a href="#file" class="anchor" name="file"><span class="octicon octicon-link"></span></a>The file pattern</h2>
|
||||
<h2><a href="#file" class="anchor" id="file"><span class="octicon octicon-link"></span></a>The file pattern</h2>
|
||||
<p>Here <b>all</b> variables must return an array. And there no specific formats. First we declare the flags and then we describe all other variables. As I am not going to describe the functions in more detail below I remind you that <code>_netctl_profiles()</code> should be generated each time:
|
||||
|
||||
{% highlight bash %}
|
||||
@ -58,7 +58,7 @@ complete -F _netctl_gui netctl-gui
|
||||
|
||||
</p>
|
||||
|
||||
<h2><a href="#flags" class="anchor" name="flags"><span class="octicon octicon-link"></span></a>Flags</h2>
|
||||
<h2><a href="#flags" class="anchor" id="flags"><span class="octicon octicon-link"></span></a>Flags</h2>
|
||||
<p>As it was said above there is no specific format, so all available flags declare by array:
|
||||
|
||||
{% highlight bash %}
|
||||
@ -79,7 +79,7 @@ _netctl_gui_arglist=(
|
||||
|
||||
</p>
|
||||
|
||||
<h2><a href="#variables" class="anchor" name="variables"><span class="octicon octicon-link"></span></a>Arrays of variables</h2>
|
||||
<h2><a href="#variables" class="anchor" id="variables"><span class="octicon octicon-link"></span></a>Arrays of variables</h2>
|
||||
<p>I just give a function that looked like this in zsh:
|
||||
|
||||
{% highlight bash %}
|
||||
@ -98,7 +98,7 @@ _netctl_profiles() {
|
||||
|
||||
</p>
|
||||
|
||||
<h2><a href="#body" class="anchor" name="body"><span class="octicon octicon-link"></span></a>Function</h2>
|
||||
<h2><a href="#body" class="anchor" id="body"><span class="octicon octicon-link"></span></a>Function</h2>
|
||||
<p>The variable <code>COMPREPLY</code> responds for completion in Bash. To keep track of the current state function <code>_get_comp_words_by_ref</code> must be called with parameters <code>cur</code> (current flag) and <code>prev</code> (previous flag, it is the state). Also some point for case are needed (variables <code>want*</code>). Function <code>compgen</code> is used for completion generation. A list of words is given after flag <code>-W</code>. (Also there is flag <code>-F</code> which requires a function as argument, but it gives warning for me.) The last argument is a current string to which you want to generate completion.</p>
|
||||
|
||||
<p>So, here is our function:
|
||||
@ -140,5 +140,5 @@ _netctl_gui() {
|
||||
|
||||
</p>
|
||||
|
||||
<h2><a href="#conclusion" class="anchor" name="conclusion"><span class="octicon octicon-link"></span></a>Conclusion</h2>
|
||||
<h2><a href="#conclusion" class="anchor" id="conclusion"><span class="octicon octicon-link"></span></a>Conclusion</h2>
|
||||
<p>File should be places to <code>/usr/share/bash-completion/completions/</code> with any name. You may found the example <a href="https://raw.githubusercontent.com/arcan1s/netctl-gui/master/sources/gui/bash-completions" title="File" type="text/plain">in my repository</a>.</p>
|
||||
|
Reference in New Issue
Block a user