200 lines
12 KiB
Plaintext
200 lines
12 KiB
Plaintext
|
|
Episode: 2073
|
||
|
|
Title: HPR2073: The power of GNU Readline - part 1
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2073/hpr2073.mp3
|
||
|
|
Transcribed: 2025-10-18 13:59:21
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
This is HPR episode 2007 to free and titled, The Power of GNU Readline Part 1.
|
||
|
|
It is hosted by Dave Morris and is about 12 minutes long.
|
||
|
|
The summary is, and a lot you can do to speed up typing by using GNU Readline.
|
||
|
|
We'll explore how in this series.
|
||
|
|
This episode of HPR is brought to you by An Honesthost.com.
|
||
|
|
Get 15% discount on all shared hosting with the offer code HPR15.
|
||
|
|
That's HPR15.
|
||
|
|
Better web hosting that's honest and fair at An Honesthost.com.
|
||
|
|
Hi everyone, this is Dave Morris and I'm going to talk to you today about a feature you probably know about.
|
||
|
|
It's called GNU Readline.
|
||
|
|
GNU Readline is actually a library and we all use it because
|
||
|
|
if we were pretty much all of us do anyway.
|
||
|
|
As long as we use the command line, we use applications that take input.
|
||
|
|
This is because GNU Readline is used in Bash and in many other tools.
|
||
|
|
It manages input, it does line editing and it gives you a command history feature.
|
||
|
|
It's very powerful.
|
||
|
|
Now I've been using Unix and later on Linux since probably the 1980s sometimes then.
|
||
|
|
I don't remember precisely when I first saw a Unix system or had one available to me,
|
||
|
|
but they were a little bit weird in the way in which you use the command line.
|
||
|
|
There were different experiences depending on what version of Unix you'd got,
|
||
|
|
but they did tend to have similar features.
|
||
|
|
I think that this was the early days of Readline or it was pre-readline.
|
||
|
|
There were things like jump to the start of the line, jump to the end of the line,
|
||
|
|
delete a character backwards, delete up to a space, delete the entire line,
|
||
|
|
those sorts of things that were available.
|
||
|
|
While Readline is the development of all that sort of stuff and it's very, very powerful
|
||
|
|
and I think it's worth learning about to some degree anyway because there is such a rich feature set.
|
||
|
|
Much more than I just summarized, I thought I would do a series with just a few episodes
|
||
|
|
in where I covered some of what Readline can do.
|
||
|
|
Really sort of the things that I use most and quite like and think you might like as well.
|
||
|
|
I want to keep the episode short because it's a pretty dry subject,
|
||
|
|
and if you're anything like me you can't take in more than a few key sequences at a time.
|
||
|
|
Plus also there's the advantage of maybe picking up a few and learning them
|
||
|
|
so that they get stuck in your muscle memory and then moving on to another set.
|
||
|
|
The source of my information for this series is the GNU Readline Manual
|
||
|
|
and I've put a link to that in the show notes.
|
||
|
|
It's really well written, it's got everything in it as most GNU manuals do.
|
||
|
|
It's a little bit overwhelming I find anyway.
|
||
|
|
So what I'm doing here is what I tend to do a lot in my shows these days
|
||
|
|
is to give you a sort of few pointers and to translate it for you in some way I guess.
|
||
|
|
If you already know you were around it, you used it a lot yourself,
|
||
|
|
you probably don't want to listen to this show.
|
||
|
|
So let's talk about the keys and notations and stuff.
|
||
|
|
The features in GNU Readline are invoked usually by multi key sequences
|
||
|
|
and these involve the control key and the so-called meta key.
|
||
|
|
The control key is the one on your keyboard marked CTRL
|
||
|
|
and the meta key is another name for the one marked ALT.
|
||
|
|
There are usually two ALT keys on a keyboard,
|
||
|
|
at least if it's a full size keyboard
|
||
|
|
and there's variability in which of these is the meta key sometimes both of them now.
|
||
|
|
So you'll have to investigate that for yourself I'm afraid.
|
||
|
|
So the notation in the GNU Readline manual is capital C hyphen K
|
||
|
|
to mean CTRL K meaning the character that's produced when you hold down the CTRL key
|
||
|
|
and press the K key.
|
||
|
|
So CTRL is sort of a shift key as you well aware I'm sure.
|
||
|
|
The meta key has a notation capital M hyphen K or meta K
|
||
|
|
for the sequence where you hold down the meta key and press the K key,
|
||
|
|
low case K and you get a particular character produced.
|
||
|
|
Now if you're unlucky enough not to have an ALT key or a meta key
|
||
|
|
then you can obtain the same result by pressing the escape key.
|
||
|
|
This time it's not a shift type key.
|
||
|
|
Just press the escape key, release it then press the K key to get the equivalent of meta K.
|
||
|
|
Some instances you can use the CTRL key and the meta key
|
||
|
|
so the notation for that would be capital M hyphen capital C hyphen low case K.
|
||
|
|
So that means hold down CTRL, hold down meta, press the low case K key.
|
||
|
|
If it was an uppercase K then you'd have to press the shift key as well
|
||
|
|
but I don't think there's too many of those but I haven't dug into that one yet.
|
||
|
|
I don't think you'd want to do that very often, I'm sure you could.
|
||
|
|
So what I want to do like I said is to keep these fairly short
|
||
|
|
and I'm going to just cover bunch of key sequences.
|
||
|
|
I haven't got very many this time because this is an introductory show.
|
||
|
|
I'm going to sort of limit myself to maybe 10 at a maximum,
|
||
|
|
probably less depending on how complex they are.
|
||
|
|
So let's dive into the first set of CTRL sequences that you probably already know.
|
||
|
|
So when you're typing stuff on the command line,
|
||
|
|
you can move forward and backwards on the line.
|
||
|
|
Say you start with the blank line, you start typing something.
|
||
|
|
You can if you want to move back one character, maybe you've admitted a letter.
|
||
|
|
You can move backwards one character.
|
||
|
|
You can either do that pressing the left arrow key
|
||
|
|
but not all keyboards have an arrow keys
|
||
|
|
or if they have their function, you have to press a function key as well.
|
||
|
|
CTRL B moves back one character so it's B for back.
|
||
|
|
Moving forward one character is CTRL F, lowercase F.
|
||
|
|
I always forget to say what case.
|
||
|
|
So it was CTRL lowercase B and CTRL lowercase F for backwards and forwards.
|
||
|
|
The next one is the backspace key.
|
||
|
|
Now this is not a key combination, it's just single key.
|
||
|
|
And you should have a backspace key on most keyboards.
|
||
|
|
It's up on the number line to the right hand side.
|
||
|
|
I'm probably telling you wrong because you've got a key board that's different from this.
|
||
|
|
But you should have something marked backspace.
|
||
|
|
And that just deletes the character to the left of the cursor that deletes backwards.
|
||
|
|
Then there's CTRL lowercase D
|
||
|
|
and that deletes the character underneath the cursor.
|
||
|
|
I've got an example at the end, which hopefully will help to clarify this.
|
||
|
|
So it's deleting effectively forwards,
|
||
|
|
given that your cursor is on a key, on a character I mean.
|
||
|
|
Backspace will delete to the left and CTRL D will delete under the cursor
|
||
|
|
and the line will shrink appropriately.
|
||
|
|
Now there's a del key, sometimes marked delete,
|
||
|
|
which is in the keypad area if you have that.
|
||
|
|
This is sometimes probably usually set up to be the same as CTRL under CTRL lowercase D.
|
||
|
|
It is on my setup, which is Debian testing with XFCE.
|
||
|
|
But in some cases it's the same as the backspace.
|
||
|
|
So you need to watch out for that and check it out and see which is which it is.
|
||
|
|
Okay, so let's look at a set of commands that you might not know.
|
||
|
|
I bet you will know some of them.
|
||
|
|
Well, I didn't know this first one.
|
||
|
|
And that is CTRL and underscore.
|
||
|
|
There is an alternative to this, which are put in the nodes,
|
||
|
|
but I won't go into it here because we'll get onto these sorts of weird commands later.
|
||
|
|
CTRL and underscore.
|
||
|
|
Now remember, most keyboards, the underscores on the top of the shifted key.
|
||
|
|
So you'd have to do CTRL shift and then the key with the underscore.
|
||
|
|
It depends on your keyboard and all sorts of things.
|
||
|
|
So what this does is it undoes the last editing command.
|
||
|
|
And it's a cumulative undo.
|
||
|
|
So you can undo repeatedly all the way back to the black line you started with.
|
||
|
|
Look at this a bit more later.
|
||
|
|
Okay, CTRL and lowercase A moves to the start of the line.
|
||
|
|
You probably know that one.
|
||
|
|
It's usually the same as the home key if you have one.
|
||
|
|
CTRL and lowercase E moves to the end of the line.
|
||
|
|
And this is usually the same as the end key if you have one of those.
|
||
|
|
The next one I had not really come across.
|
||
|
|
I've not really used, not got it built into my muscle memory yet.
|
||
|
|
And that is meta followed by lowercase F.
|
||
|
|
Meta lowercase F.
|
||
|
|
So you would hold the ALT key, whichever one is meta on your system and press lowercase F.
|
||
|
|
What this does is move forward a word.
|
||
|
|
And we need to define what a word is.
|
||
|
|
And it's what you'd expect it to be a sequence of letters and numbers.
|
||
|
|
You can, if you move backwards down a line, you can move forward by word.
|
||
|
|
And of course you can also move backwards by words with meta and with lowercase B.
|
||
|
|
Now, last one in this block, because I don't know about you,
|
||
|
|
I'm reaching my forgetting limit.
|
||
|
|
I don't think I could retain many more than the last one is CTRL L.
|
||
|
|
You probably know that one.
|
||
|
|
So if you're in the middle of typing a line for whatever reason you want to clear the screen,
|
||
|
|
you will do that.
|
||
|
|
And it will then reprint the line you're working on at the top of the screen.
|
||
|
|
If it's a blank line, you'll just get a blank line at the top of the screen.
|
||
|
|
But it clears the screen.
|
||
|
|
I don't think I knew that it left the command you were typing at the top of the screen when you did that.
|
||
|
|
I thought it just cleared the whole thing.
|
||
|
|
I've never done that, but I must get in the habit of doing that.
|
||
|
|
Okay, so I thought what I would do to try and explain how to use these,
|
||
|
|
which is go through a little example.
|
||
|
|
And of course there's an audio podcast.
|
||
|
|
I can't really draw your picture of it or, you know, do a movie or something.
|
||
|
|
I did toy with doing an animated gif of stuff, but I decided not to.
|
||
|
|
So I'm just going to try and read out what something you could do and what the effects would be.
|
||
|
|
See how that goes?
|
||
|
|
So if you're at a terminal and you typed the quick brown fox, those four words on no blank line,
|
||
|
|
then after the x of fox, you pressed meta-locase b.
|
||
|
|
Then that moves backwards the word.
|
||
|
|
Since you're on the x, or just after the x, it will move backwards to the beginning of the f of fox.
|
||
|
|
If you pressed meta-locase b again, then the cursor would move to the b of brown.
|
||
|
|
And if you pressed control-locase-d, the b would be deleted.
|
||
|
|
Then the cursor's on the r of brown.
|
||
|
|
Effectively, the line has been moved, the bit of the line after your cursor has been moved up and filled the gap.
|
||
|
|
Then if you typed control and underscore, the b would be restored.
|
||
|
|
But this time the cursor's on the r because it hasn't moved the cursor back to where you were when there was when you deleted the b.
|
||
|
|
Then if you pressed control underscore again,
|
||
|
|
well, there was only really one edit command on that line, which was to delete the b. You restored that.
|
||
|
|
So the only other action was that you typed the quick brown fox.
|
||
|
|
So it undoes that and the whole line is blank.
|
||
|
|
The entire text is deleted.
|
||
|
|
So that's how you can use this collection of things.
|
||
|
|
Okay, that's all I'm going to talk about this time.
|
||
|
|
The links contain a pointer to the Wikipedia article on Gnu Readline,
|
||
|
|
which is actually quite good and covers a number of these sequences,
|
||
|
|
but not all.
|
||
|
|
And it missed some of the ones that I thought were useful.
|
||
|
|
So that's why I'm doing this, really.
|
||
|
|
And the Gnu Readline manual is indicated.
|
||
|
|
So you can have a look at that as well.
|
||
|
|
Okay, I hope you find that useful.
|
||
|
|
Bye now.
|
||
|
|
You've been listening to Hecker Public Radio at HeckerPublicRadio.org.
|
||
|
|
We are a community podcast network that releases shows every weekday, Monday through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by an HPR listener like yourself.
|
||
|
|
If you ever thought of recording a podcast,
|
||
|
|
then click on our contributing to find out how easy it really is.
|
||
|
|
Hecker Public Radio was founded by the digital dog pound and the Infonomicon Computer Club.
|
||
|
|
And it's part of the binary revolution at binrev.com.
|
||
|
|
If you have comments on today's show,
|
||
|
|
please email the host directly, leave a comment on the website
|
||
|
|
or record a follow-up episode yourself.
|
||
|
|
Unless otherwise status, today's show is released on the creative comments,
|
||
|
|
attribution, share a light, 3.0 license.
|