Move under www to ease rsync
This commit is contained in:
131
www/eps/hpr2453/hpr2453_full_shownotes.html
Executable file
131
www/eps/hpr2453/hpr2453_full_shownotes.html
Executable file
@@ -0,0 +1,131 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="generator" content="pandoc">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||||
<meta name="author" content="Dave Morriss">
|
||||
<title>The power of GNU Readline - part 2 (HPR Show 2453)</title>
|
||||
<style type="text/css">code{white-space: pre;}</style>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link rel="stylesheet" href="http://hackerpublicradio.org/css/hpr.css">
|
||||
</head>
|
||||
|
||||
<body id="home">
|
||||
<div id="container" class="shadow">
|
||||
<header>
|
||||
<h1 class="title">The power of GNU Readline - part 2 (HPR Show 2453)</h1>
|
||||
<h2 class="author">Dave Morriss</h2>
|
||||
<hr/>
|
||||
</header>
|
||||
|
||||
<main id="maincontent">
|
||||
<article>
|
||||
<header>
|
||||
<h1>Table of Contents</h1>
|
||||
<nav id="TOC">
|
||||
<ul>
|
||||
<li><a href="#recap-of-keys-and-notation">Recap of Keys and Notation</a></li>
|
||||
<li><a href="#key-sequences-and-the-desktop">Key sequences and the desktop</a></li>
|
||||
<li><a href="#going-in-for-the-kill">Going in for the kill</a></li>
|
||||
<li><a href="#examples">Examples</a><ul>
|
||||
<li><a href="#example-1">Example 1</a></li>
|
||||
<li><a href="#example-2">Example 2</a></li>
|
||||
</ul></li>
|
||||
<li><a href="#links">Links</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<h2 id="recap-of-keys-and-notation">Recap of Keys and Notation</h2>
|
||||
<p>(Feel free to skip this if you are up to speed with the keys and notation we used before.)</p>
|
||||
<blockquote>
|
||||
<p>In the <a href="http://www.hackerpublicradio.org/eps.php?id=2073" title="The power of GNU Readline - part 1">last episode</a> we saw that most of the features in GNU Readline are invoked by multi-key sequences. These involve the <code>Control</code> key and the so-called <code>Meta</code> key. The <code>Control</code> key is usually marked <strong>Ctrl</strong> on the keyboard. The <code>Meta</code> key is the key marked <strong>Alt</strong>.</p>
|
||||
<p>The notation used in the GNU Readline manual is <code>C-k</code> for ‘<em>Control-k</em>’, meaning the character produced when the <code>k</code> key is pressed while the <code>Control</code> key is being held down.</p>
|
||||
<p>For the <code>Meta</code> key the notation <code>M-k</code> (<strong>Meta-k</strong>) means the character produced when the <code>k</code> key is pressed while the <code>Meta</code> key is being held down.</p>
|
||||
<p>If your keyboard does not have a <code>Meta</code> key then the same result can be obtained for <code>M-k</code> by pressing the <code>Esc</code> key, releasing it, then pressing the <code>k</code> key.</p>
|
||||
<p>In some instances both the <code>Control</code> and the <code>Meta</code> key might be used, so <code>M-C-k</code> would mean the character produced when the <code>k</code> key is pressed while the <code>Meta</code> and <code>Control</code> keys are being held down.</p>
|
||||
</blockquote>
|
||||
<p>Note that in the last episode we looked at <code>C-d</code> as a way of deleting the character under the cursor (the same as the <code>Del</code> key, at least in my case). This key sequence has another meaning which we didn’t cover. If the input line is empty and the cursor is on the beginning of the line, <code>C-d</code> sends an ‘end of file signal’. This can stop a script or program waiting for input or kill the terminal emulator amongst other effects.</p>
|
||||
<h2 id="key-sequences-and-the-desktop">Key sequences and the desktop</h2>
|
||||
<p>Depending on which desktop you use you might find that some of the key sequences used by GNU Readline do not work the way they are documented.</p>
|
||||
<p>One of the areas of confusion is with the <strong>Backspace</strong> and <strong>Delete</strong> keys. In my experience of using various flavours of Unix over the years (SunOS, Solaris, DomainOS, HP-UX, Ultrix, OSF/1, TRU64 Unix), the behaviour of these keys was the cause of much confusion.</p>
|
||||
<p>As explained in the initial part of <a href="http://www.ibb.net/~anne/keyboard.html" title="Consistent BackSpace and Delete Configuration">this article</a> the original was in the context of paper tape. The <strong>Backspace</strong> key would move the tape backwards one place and the <strong>Delete</strong> key would then overpunch the position with all 1’s, a bit like the way typists used to cancel out an individual character on a typewriter.</p>
|
||||
<p>The behaviour of using the <strong>Backspace</strong> key for deleting characters backward, and the <strong>Delete</strong> key for deleting the character under the cursor did not really settle down until the late 1990’s.</p>
|
||||
<h2 id="going-in-for-the-kill">Going in for the kill</h2>
|
||||
<p>The term <em>kill</em> is used in the <a href="https://tiswww.cwru.edu/php/chet/readline/rluserman.html" title="GNU Readline Manual">GNU manual</a> to mean deleting text while saving it away for later. There you will also find the term <em>yank</em> meaning to re-insert deleted text back again. This is a bit confusing (not consistent with <code>sed</code> or <code>vim</code> for example) so I will not be using these terms (though I’ll refer to them in the notes for completeness).</p>
|
||||
<p>As they point out, the more modern terminology for these actions is <em>cut</em> and <em>paste</em>.</p>
|
||||
<p>Deleted (cut or killed) text is stored in a place called the <em>kill-ring</em> and can be restored. Consecutive kills cause the text to be accumulated into one unit which can be yanked (pasted) all at once. Commands which do not kill text separate the chunks of text on the kill ring.</p>
|
||||
<dl>
|
||||
<dt><strong><code>C-k</code></strong> <small>(<code>Control-k</code>)</small></dt>
|
||||
<dd>Delete (<em>Kill</em>) the text from the current cursor position to the end of the line. Deletes everything to the right.
|
||||
</dd>
|
||||
<dt><strong><code>M-d</code></strong> <small>(<code>Meta-d</code>)</small></dt>
|
||||
<dd>Delete (<em>Kill</em>) forward from the cursor to the end of the current word, or, if between words, to the end of the next word. Word boundaries are the same as those used by <code>M-f</code> (move forward a word).<br />
|
||||
The space after the word is not deleted and the space before it is only deleted if the cursor is there.
|
||||
</dd>
|
||||
<dt><strong><code>M-DEL</code></strong> (<strong><code>M-Backspace</code></strong>) <small>(<code>Meta-DEL</code> or <code>Meta-Backspace</code>)</small></dt>
|
||||
<dd>Delete (<em>Kill</em>) backward from the cursor to the start of the current word, or, if between words, to the start of the previous word. Word boundaries are the same as those used by <code>M-b</code> (move backward a word).<br />
|
||||
<br />
|
||||
<strong>Note</strong>: I find that this functionality is available as <code>M-Backspace</code> on my workstation, not as <code>M-DEL</code>.<br />
|
||||
<br />
|
||||
This feature is very useful for deleting a filename component for example. We’ll look at this in the Examples section below.
|
||||
</dd>
|
||||
<dt><strong><code>C-w</code></strong> <small>(<code>Control-w</code>)</small></dt>
|
||||
<dd>Delete (<em>Kill</em>) backwards from the cursor to the previous whitespace. This is different from <code>M-DEL</code> because the word boundaries differ.
|
||||
</dd>
|
||||
<dt><strong><code>C-y</code></strong> <small>(<code>Control-y</code>)</small></dt>
|
||||
<dd>Paste (<em>Yank</em>) the most recently killed text back into the buffer at the cursor.
|
||||
</dd>
|
||||
<dt><strong><code>M-y</code></strong> <small>(<code>Meta-y</code>)</small></dt>
|
||||
<dd>Rotate the <em>kill-ring</em>, and paste (<em>yank</em>) the new top. You can only do this if the prior command is <code>C-y</code> or <code>M-y</code>.
|
||||
</dd>
|
||||
</dl>
|
||||
<h2 id="examples">Examples</h2>
|
||||
<h3 id="example-1">Example 1</h3>
|
||||
<p>Type the following on the command line and position the cursor to the ‘m’ of <em>miles</em> (Hint: you can use the <code>M-b</code> command repeatedly for this). The circumflex (‘<code>^</code>’) below the line shows the cursor position:</p>
|
||||
<pre><code>$ echo How many miles to Babylon
|
||||
^</code></pre>
|
||||
<p>Press <code>C-k</code>, that is, hold the <code>Control</code> key and press <code>k</code>. The text from the cursor to the end of the line is deleted. Move the cursor to the start of the string over the ‘H’ of <em>How</em> (you could press <code>M-b</code> twice):</p>
|
||||
<pre><code>$ echo How many
|
||||
^</code></pre>
|
||||
<p>Press <code>C-y</code> to paste (<em>yank</em>) back the text we deleted (<em>killed</em>):</p>
|
||||
<pre><code>$ echo miles to BabylonHow many
|
||||
miles to BabylonHow many</code></pre>
|
||||
<p>Not particularly useful, but you get the idea.</p>
|
||||
<h3 id="example-2">Example 2</h3>
|
||||
<p>As <code>root</code> you want to check various log files. First the <code>mosquitto</code> log:</p>
|
||||
<pre><code>$ tail /var/log/mosquitto/mosquitto.log</code></pre>
|
||||
<p>Of course, you will have created this line in the first place by typing:</p>
|
||||
<pre><code>$ tail /var/log/mos</code></pre>
|
||||
<p>then pressing the <code>Tab</code> key to get:</p>
|
||||
<pre><code>$ tail /var/log/mosquitto/</code></pre>
|
||||
<p>Then pressing <code>Tab</code> again fills in the rest (assuming your <code>/var/log/mosquitto/</code> directory only contains files starting with <code>mosquitto.log</code>).</p>
|
||||
<p>Now you might want to check the system log in case it holds any clues to the problem you’re investigating, so you recall the last line:</p>
|
||||
<pre><code>$ tail /var/log/mosquitto/mosquitto.log</code></pre>
|
||||
<p>You press <code>M-Backspace</code> three times to delete the last three elements and get:</p>
|
||||
<pre><code>$ tail /var/log/</code></pre>
|
||||
<p>You can then type <code>syslog</code> to get the command:</p>
|
||||
<pre><code>$ tail /var/log/syslog</code></pre>
|
||||
<p>As one last demonstration: if you were to remove the <code>syslog</code> you just typed using <code>M-Backspace</code> you would be able to restore it with <code>C-y</code>, then if you typed <code>M-y</code> you’d see <code>syslog</code> replaced by <code>mosquitto/mosquitto.log</code>.</p>
|
||||
<p>This is because the ‘kill ring’ contained the <code>syslog</code> text after it had been deleted, but it also contained the earlier deletion. After typing <code>Ctrl-y</code> to restore the last deletion the key sequence <code>M-y</code> rotated the ring and restored the original deletion. You can repeat <code>M-y</code> to repeat this process with the kill ring.</p>
|
||||
<p>Hopefully you can see the power of GNU Readline to do some useful stuff when creating and editing a command.</p>
|
||||
<h2 id="links">Links</h2>
|
||||
<ul>
|
||||
<li><a href="http://www.ibb.net/~anne/keyboard.html">Consistent BackSpace and Delete Configuration</a></li>
|
||||
<li>Wikipedia article on <a href="https://en.wikipedia.org/wiki/GNU_Readline"><em>GNU Readline</em></a></li>
|
||||
<li><a href="https://tiswww.cwru.edu/php/chet/readline/rluserman.html"><em>GNU Readline</em> manual</a> (Note that the widely advertised address http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html seems not to work any more. This one, which I found through the main GNU site, seems OK though)</li>
|
||||
<li>Previous episode:
|
||||
<ul>
|
||||
<li><a href="http://www.hackerpublicradio.org/eps.php?id=2073">The power of GNU Readline - part 1</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<!--
|
||||
vim: syntax=markdown:ts=4:sw=4:ai:et:tw=78:fo=tcqn:fdm=marker
|
||||
-->
|
||||
</article>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user