Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can determine the character sequence emitted by a key by pressing <kbd>Ctrl</kbd>-<kbd>v</kbd> at the command line, then pressing the key you're interested in. On my system for <kbd>F12</kbd>, I get <code>^[[24~</code>. The <code>^[</code> represents <kbd>Esc</kbd>. Different types of terminals or terminal emulators can emit different codes for the same key.</p> <p>At a Bash prompt you can enter a command like this to enable the key macro so you can try it out.</p> <pre><code>bind '"\e[24~":"foobar"' </code></pre> <p>Now, when you press <kbd>F12</kbd>, you'll get "foobar" on the command line ready for further editing. If you wanted a keystroke to enter a command immediately, you can add a newline:</p> <pre><code>bind '"\e[24~":"pwd\n"' </code></pre> <p>Now when you press <kbd>F12</kbd>, you'll get the current directory displayed without having to press <kbd>Enter</kbd>. What if you've already typed something on the line and you use this which automatically executes? It could get messy. However, you could clear the line as part of your macro:</p> <pre><code>bind '"\e[24~":"\C-k \C-upwd\n"' </code></pre> <p>The space makes sure that the <kbd>Ctrl</kbd>-<kbd>u</kbd> has something to delete to keep the bell from ringing.</p> <p>Once you've gotten the macro working the way you want, you can make it persistent by adding it to your <code>~/.inputrc</code> file. There's no need for the <code>bind</code> command or the outer set of single quotes:</p> <pre><code>"\e[24~":"\C-k \C-upwd\n" </code></pre> <p><strong>Edit:</strong></p> <p>You can also create a key binding that will execute something without disturbing the current command line.</p> <pre><code>bind -x '"\eW":"who"' </code></pre> <p>Then while you're typing a command that requires a username, for example, and you need to know the names of user who are logged in, you can press <kbd>Alt</kbd>-<kbd>Shift</kbd>-<kbd>W</kbd> and the output of <code>who</code> will be displayed and the prompt will be re-issued with your partial command intact and the cursor in the same position in the line.</p> <p>Unfortunately, this doesn't work properly for keys such as <kbd>F12</kbd> which output more than two characters. In some cases this can be worked around.</p> <p>The command (<code>who</code> in this case) could be any executable - a program, script or function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload