File: commandline.html

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (346 lines) | stat: -rw-r--r-- 21,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>commandline - set or get the current command line buffer &#8212; fish-shell 4.2.1 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4da8bbd6" />
    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=f89b4716" />
    <script src="../_static/documentation_options.js?v=6fb65176"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="complete - edit command-specific tab-completions" href="complete.html" />
    <link rel="prev" title="command - run a program" href="command.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/fish.png" />
     

  </head><body><div id="fmain">  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="../_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="../index.html">fish-shell 4.2.1 documentation</a> &#187;
    

          <li class="nav-item nav-item-1"><a href="../commands.html" accesskey="U">Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">commandline - set or get the current command line buffer</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../../current/">See the latest release.</a>
    </div>

      </ul>
    </div>    

    <div class="document">
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<div>
<h3><a href="../index.html">Documents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">Frequently asked questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../interactive.html">Interactive use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../language.html">The fish language</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../commands.html">Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fish_for_bash_users.html">Fish for bash users</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../completions.html">Writing your own completions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../prompt.html">Writing your own prompt</a></li>
<li class="toctree-l1"><a class="reference internal" href="../design.html">Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="../relnotes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../terminal-compatibility.html">Terminal Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">Contributing To Fish</a></li>
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
</ul>

</div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<div>
<h4><a href="../index.html">Sections</a></h4>
<ul>
<li><a class="reference internal" href="#">commandline - set or get the current command line buffer</a><ul>
<li><a class="reference internal" href="#synopsis">Synopsis</a></li>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>

</div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="commandline-set-or-get-the-current-command-line-buffer">
<h1>commandline - set or get the current command line buffer<a class="headerlink" href="#commandline-set-or-get-the-current-command-line-buffer" title="Link to this heading">¶</a></h1>
<section id="synopsis">
<h2>Synopsis<a class="headerlink" href="#synopsis" title="Link to this heading">¶</a></h2>
<div class="highlight-fish-synopsis notranslate"><div class="highlight"><pre><span></span><span class="nf">commandline</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">OPTIONS</span><span class="g g-Other">]</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">CMD</span><span class="g g-Other">]</span>
</pre></div>
</div>
</section>
<section id="description">
<h2>Description<a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">commandline</span></code> can be used to set or get the current contents of the command line buffer.</p>
<p>With no parameters, <code class="docutils literal notranslate"><span class="pre">commandline</span></code> returns the current value of the command line.</p>
<p>With <strong>CMD</strong> specified, the command line buffer is erased and replaced with the contents of <strong>CMD</strong>.</p>
<p>The following options are available:</p>
<dl class="simple">
<dt><strong>-C</strong> or <strong>--cursor</strong></dt><dd><p>Set or get the current cursor position, not the contents of the buffer.
If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.
If one of the options <strong>-j</strong>, <strong>-p</strong> or <strong>-t</strong> is given, the position is relative to the respective substring instead of the entire command line buffer.</p>
</dd>
<dt><strong>-B</strong> or <strong>--selection-start</strong></dt><dd><p>Get current position of the selection start in the buffer.</p>
</dd>
<dt><strong>-E</strong> or <strong>--selection-end</strong></dt><dd><p>Get current position of the selection end in the buffer.</p>
</dd>
<dt><strong>-f</strong> or <strong>--function</strong></dt><dd><p>Causes any additional arguments to be interpreted as input functions, and puts them into the queue, so that they will be read before any additional actual key presses are.
This option cannot be combined with any other option.
See <a class="reference internal" href="bind.html"><span class="doc">bind</span></a> for a list of input functions.</p>
</dd>
<dt><strong>-h</strong> or <strong>--help</strong></dt><dd><p>Displays help about using this command.</p>
</dd>
</dl>
<p>The following options change the way <code class="docutils literal notranslate"><span class="pre">commandline</span></code> updates the command line buffer:</p>
<dl class="simple">
<dt><strong>-a</strong> or <strong>--append</strong></dt><dd><p>Do not remove the current commandline, append the specified string at the end of it.</p>
</dd>
<dt><strong>-i</strong>, <strong>--insert</strong> or <strong>--insert-smart</strong></dt><dd><p>Do not remove the current commandline, insert the specified string at the current cursor position.
The <strong>--insert-smart</strong> option turns on a Do-What-I-Mean (DWIM) mode: it strips any <strong>$</strong> prefix from the first command on each line.</p>
</dd>
<dt><strong>-r</strong> or <strong>--replace</strong></dt><dd><p>Remove the current commandline and replace it with the specified string (default)</p>
</dd>
</dl>
<p>The following options change what part of the commandline is printed or updated:</p>
<dl class="simple">
<dt><strong>-b</strong> or <strong>--current-buffer</strong></dt><dd><p>Select the entire commandline, not including any displayed autosuggestion (default).</p>
</dd>
<dt><strong>-j</strong> or <strong>--current-job</strong></dt><dd><p>Select the current job - a <strong>job</strong> here is one pipeline.
Stops at logical operators or terminators (<strong>;</strong>, <strong>&amp;</strong>, and newlines).</p>
</dd>
<dt><strong>-p</strong> or <strong>--current-process</strong></dt><dd><p>Select the current process - a <strong>process</strong> here is one command.
Stops at logical operators, terminators, and pipes.</p>
</dd>
<dt><strong>-s</strong> or <strong>--current-selection</strong></dt><dd><p>Selects the current selection</p>
</dd>
<dt><strong>-t</strong> or <strong>--current-token</strong></dt><dd><p>Selects the current token</p>
</dd>
<dt><strong>--search-field</strong></dt><dd><p>Use the pager search field instead of the command line. Returns false if the search field is not shown.</p>
</dd>
<dt><strong>--input=INPUT</strong></dt><dd><p>Operate on this string instead of the commandline. Useful for using options like <strong>--tokens-expanded</strong>.</p>
</dd>
</dl>
<p>The following options change the way <code class="docutils literal notranslate"><span class="pre">commandline</span></code> prints the current commandline buffer:</p>
<dl class="simple">
<dt><strong>-c</strong> or <strong>--cut-at-cursor</strong></dt><dd><p>Only print selection up until the current cursor position.
If combined with <code class="docutils literal notranslate"><span class="pre">--tokens-expanded</span></code>, this will print up until the last completed token - excluding the token the cursor is in.
This is typically what you would want for instance in completions.
To get both, use both <code class="docutils literal notranslate"><span class="pre">commandline</span> <span class="pre">--cut-at-cursor</span> <span class="pre">--tokens-expanded;</span> <span class="pre">commandline</span> <span class="pre">--cut-at-cursor</span> <span class="pre">--current-token</span></code>,
or <code class="docutils literal notranslate"><span class="pre">commandline</span> <span class="pre">-cx;</span> <span class="pre">commandline</span> <span class="pre">-ct</span></code> for short.</p>
</dd>
<dt><strong>-x</strong> or <strong>--tokens-expanded</strong></dt><dd><p>Perform argument expansion on the selection and print one argument per line.
Command substitutions are not expanded but forwarded as-is.</p>
</dd>
<dt><strong>-o</strong>, <strong>tokenize</strong>, <strong>--tokens-raw</strong></dt><dd><p>Deprecated; do not use.</p>
</dd>
</dl>
<p>If <code class="docutils literal notranslate"><span class="pre">commandline</span></code> is called during a call to complete a given string using <code class="docutils literal notranslate"><span class="pre">complete</span> <span class="pre">-C</span> <span class="pre">STRING</span></code>, <code class="docutils literal notranslate"><span class="pre">commandline</span></code> will consider the specified string to be the current contents of the command line.</p>
<p>The following options output metadata about the commandline state:</p>
<dl class="simple">
<dt><strong>-L</strong> or <strong>--line</strong></dt><dd><p>If no argument is given, print the line that the cursor is on, with the topmost line starting at 1.
Otherwise, set the cursor to the given line.</p>
</dd>
<dt><strong>--column</strong></dt><dd><p>If no argument is given, print the 1-based offset from the start of the line to the cursor position in Unicode code points.
Otherwise, set the cursor to the given code point offset.</p>
</dd>
<dt><strong>-S</strong> or <strong>--search-mode</strong></dt><dd><p>Evaluates to true if the commandline is performing a history search.</p>
</dd>
<dt><strong>-P</strong> or <strong>--paging-mode</strong></dt><dd><p>Evaluates to true if the commandline is showing pager contents, such as tab completions.</p>
</dd>
<dt><strong>--paging-full-mode</strong></dt><dd><p>Evaluates to true if the commandline is showing pager contents, such as tab completions and all lines are shown (no “&lt;n&gt; more rows” message).</p>
</dd>
<dt><strong>--is-valid</strong></dt><dd><p>Returns true when the commandline is syntactically valid and complete.
If it is, it would be executed when the <code class="docutils literal notranslate"><span class="pre">execute</span></code> bind function is called.
If the commandline is incomplete, return 2, if erroneous, return 1.</p>
</dd>
<dt><strong>--showing-suggestion</strong></dt><dd><p>Evaluates to true (i.e. returns 0) when the shell is currently showing an automatic history completion/suggestion, available to be consumed via one of the <cite>forward-</cite> bindings.
For example, can be used to determine if moving the cursor to the right when already at the end of the line would have no effect or if it would cause a completion to be accepted (note that <cite>forward-char-passive</cite> does this automatically).</p>
</dd>
</dl>
</section>
<section id="example">
<h2>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">commandline</span> <span class="pre">-j</span> <span class="pre">$history[3]</span></code> replaces the job under the cursor with the third item from the command line history.</p>
<p>If the commandline contains</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;_ </span><span class="nf">echo</span><span class="w"> </span><span class="o">$flounder</span><span class="w"> </span><span class="p">&gt;&amp;2</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">less</span><span class="p">;</span><span class="w"> </span><span class="o">and</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="o">$catfish</span>
</pre></div>
</div>
<p>(with the cursor on the “o” of “flounder”)</p>
<p>The <code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">$flounder</span> <span class="pre">&gt;&amp;</span></code> is the first process, <code class="docutils literal notranslate"><span class="pre">less</span></code> the second and <code class="docutils literal notranslate"><span class="pre">and</span> <span class="pre">echo</span> <span class="pre">$catfish</span></code> the third.</p>
<p><code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">$flounder</span> <span class="pre">&gt;&amp;2</span> <span class="pre">|</span> <span class="pre">less</span></code> is the first job, <code class="docutils literal notranslate"><span class="pre">and</span> <span class="pre">echo</span> <span class="pre">$catfish</span></code> the second.</p>
<p><strong>$flounder</strong> is the current token.</p>
<p>The most common use for something like completions is</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">set</span><span class="w"> </span><span class="no">-l</span><span class="w"> </span><span class="no">tokens</span><span class="w"> </span><span class="o">(</span><span class="nf">commandline</span><span class="w"> </span><span class="no">-xpc</span><span class="o">)</span>
</pre></div>
</div>
<p>which gives the current <em>process</em> (what is being completed), tokenized into separate entries, up to but excluding the currently being completed token</p>
<p>If you are then also interested in the in-progress token, add</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">set</span><span class="w"> </span><span class="no">-l</span><span class="w"> </span><span class="no">current</span><span class="w"> </span><span class="o">(</span><span class="nf">commandline</span><span class="w"> </span><span class="no">-ct</span><span class="o">)</span>
</pre></div>
</div>
<p>Note that this makes it easy to render fish’s infix matching moot - if possible it’s best if the completions just print all possibilities and leave the matching to the current token up to fish’s logic.</p>
<p>More examples:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;_ </span><span class="nf">commandline</span><span class="w"> </span><span class="no">-t</span>
<span class="go">$flounder</span>
<span class="gp">&gt;_ </span><span class="nf">commandline</span><span class="w"> </span><span class="no">-ct</span>
<span class="go">$fl</span>
<span class="gp">&gt;_ </span><span class="nf">commandline</span><span class="w"> </span><span class="no">-b</span><span class="w"> </span><span class="c"># or just commandline</span>
<span class="go">echo $flounder &gt;&amp;2 | less; and echo $catfish</span>
<span class="gp">&gt;_ </span><span class="nf">commandline</span><span class="w"> </span><span class="no">-p</span>
<span class="go">echo $flounder &gt;&amp;2</span>
<span class="gp">&gt;_ </span><span class="nf">commandline</span><span class="w"> </span><span class="no">-j</span>
<span class="go">echo $flounder &gt;&amp;2 | less</span>
</pre></div>
</div>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div> 
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="../_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="../index.html">fish-shell 4.2.1 documentation</a> &#187;
    

          <li class="nav-item nav-item-1"><a href="../commands.html" >Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">commandline - set or get the current command line buffer</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../../current/">See the latest release.</a>
    </div>

      </ul>
    </div>  
    <div class="footer">
    &copy; Copyright fish-shell developers.
    <br />
    <a href="https://github.com/fish-shell/fish-shell/issues">Found a bug</a>?
    <br />

    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
</div>

<script type="text/javascript">
 FISH_DOCS_VERSION = "4.2";

 function copy_to_clipboard(it) {
     // Find the pre tag we're interested in.
     var pre = it.target;
     while (pre.tagName != "PRE") pre = pre.parentNode;
     var txt = "";
     // Cheesy: If we have a prompt,
     // we only copy prompted lines,
     // by splitting and matching and stuff
     if (pre.querySelector('span.gp')) {
         var texts= [];
         for (var line of pre.innerText.split('\n')) {
             if (line.match(/^>_?.*/)) {
                 texts.push(line.replace(/^>_?/, ""));
             }
         }
         txt = texts.join("\n");
     } else {
         // Even cheesier: If we don't have a prompt, we remove the button text from the end.
         var txt = pre.innerText.substring(0, pre.innerText.length - it.target.innerText.length).trim();
     }

     navigator.clipboard.writeText(txt).then(function() {
         // Success - set the text to indicate it,
         // then set it back after 2 seconds.
         var span = pre.querySelector("button span");
         if (span) {
             var oldText = span.innerText;
             span.innerText = "COPIED!";
             setTimeout(function() {
                 span.innerText = oldText;
             }, 2000);
         }
     }, function() {
     });
 }

  (function () {
      // Add copy buttons to all the codeblocks.
      var codeblocks = document.querySelectorAll('div > pre');

      var button = document.createElement('button');
      var span = document.createElement('span');
      span.innerText = "COPY";
      button.appendChild(span);

      for (var i of codeblocks) {
          var newButton = button.cloneNode(true);
          newButton.addEventListener('click', copy_to_clipboard);
          i.appendChild(newButton);
      }
  })();
</script>

  </body>
</html>