Episode: 4372
Title: HPR4372: The power of GNU Readline - part 4
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr4372/hpr4372.mp3
Transcribed: 2025-10-25 23:50:27

---

This is hacker public radio episode 4372 for Tuesday the 6th of May 2025.
Today's show is entitled The Power of GNU Readline Part 4.
It is part of the series GNU Readline.
It is hosted by some guy on the internet and is about 11 minutes long.
It carries a clean flag.
The summary is Escodi Talks about Vice-Settings and GNU Readline.
Hello and welcome to another episode of hacker public radio.
I am your host, some guy on the internet.
Today is a continuation of The Power of GNU Readline.
This will be part 4.
Dave Moore originally started this series.
He contributed parts 1 through 3.
I recommend you check them out and the links will be in the show notes.
Also in the show notes, a couple of prerequisites.
Look those over.
If you are novice, you definitely want to have your backups in order.
That's with anything that you do, you want to start off with decent backups and move
from there.
Alright, so when Dave Moore is covered GNU Readline, he covered it from the EMAX perspective
or at least that's the way I like to put it because everything is done with EMAX key bindings.
I am a VAM user.
There is no criticism.
Both are great tools.
You just choose the one you want and because I am very comfortable with them, I want
my terminal to behave like them and I discovered that GNU Readline is the way that you go about
making that happen.
So the first thing you want to do, you want to look over the documentation, linking the
show notes.
But if you are hoping to terminal, head on over to slash Etsy, you will see a file called
inputrc.
That's the default system-wide configuration file for GNU Readline.
You can copy that file over into your home directory and rename it dot inputrc.
Now if you restart your session after that, your new session will begin sourcing or binding
that file.
You can also do bind to, you know, switch your current session to use that file.
In the show notes, I have a link also to my GitHub directory, my GitHub, whatever.
You'll be able to see my settings that I'm using in my inputrc and I'll be handling
things from the VIM perspective.
So first of first, in your inputrc, you want to be telling it that you want to use VIMode.
So you're going to do set editing mode V. After that, you want to easily distinguish between
insert mode and command mode because unlike VIM when you're in the actual program VIM,
which has that status bar that shows you these things, at the terminal, you're not going
to have an indicator.
So you need to set one and, you know, it's just a string that you're going to be adding
to the, you know, base of your prompt.
You can use emojis and other things.
I just use a colon i for insert mode colon c for command mode.
So that way I can easily look over there and see which mode it man.
This is especially helpful when you first change over because even though you know how
to use VIM, you know, if you've been already using your terminal under this eMac style for
however long, you might forget that you're starting out in command mode or whatever and
wondering why nothing's happening.
So after setting these identifiers, we then want to go ahead and set up the f statement,
which is going to basically say f our mode is in v, follow these steps or set these parameters
or whatever.
And you set the first, well, these things kind of happen in order.
So first I start off with command mode, all of my command mode settings happen first.
And then finally I throw in a few of the insert mode stuff at the, at the bottom.
They're all contained within the same f statement, but again, it happens in order.
So if you start trying to mix, you know, command mode and insert mode, it's going to get
a little wonky.
And when you, another thing to remember, when you change from modes, it's weird as well.
So like when you're already in command mode and you change to insert mode, if you want
to change back to command mode, you have to use VIM movement mode.
That'll switch you back to command mode.
So the documentation will go over a lot of this stuff, but it's going to look weird.
And you're not going to have a very clear idea of how to implement it.
And that's where the input RC file that I'm showing you guys comes in.
And by the way, there's plenty of this stuff all over the internet because that's, you
know, again, that's what I did.
I went looking for somebody who's already put in all the work because think about it.
I can do it myself, right?
Like imagine we can all reinvent the wheel, but why would you?
This is the beauty of open source.
Someone else has already went through all of the work designing and making something that
works and provided it online.
Use it.
So we run through all of the different commands that we want to run in our command mode first.
So you know, things like doing a capital D will delete the entire line, you know, just
like in them, you can do DD and I think you can do capital D to do that, whatever.
But same thing for DD, if you want to just do DD from command mode, it would operate
just like in them.
It would delete the entire line.
Same thing with maneuvering around on the line.
So I can't remember what the Emax ways of doing things control A and all of that crap to
kind of like move to different positions.
Well, you're going to be using the same things you know of from Vi, right?
You can jump to the beginning of the line and into insert mode, just by doing the capital
I.
Same thing.
If you want to jump to the end of the line and then switch to insert mode from command mode
capital A, right?
So all the things you know from them, just carry right on over to the command line.
Some of them aren't going to be just based, you know, some of them aren't going to happen
right away.
So that's why you need to configure it a little bit and it's absolutely fantastic.
You can also do things like macros as well.
So you'll see in my command mode section, I have a short macro down there at the bottom
to source files.
I'm sure I talked about this before, but some of my my scripts, I use like a control panel
nomenclature where you will have, you know, certain scripts that are buttons and others
that are switches.
The buttons are meant to be standalone run as is and, you know, sub processes, whereas
the switches are sourced into current environment.
Well, when I want to source a switch, I have a macro here that lets me do just like I
wouldn't them.
So in them, I do leader SO, which would then, you know, do a command SO to source a file
in them.
Well, I do the same thing here at the command line, except in step for leader.
I do semi, semi colon, semi colon SO will source whatever file I have typed out.
So I'll just go ahead and type out my switch, do a type complete to, you know, complete
the switch that I want and then I'll do my little source macro here and it'll automatically
source that into my environment and we're good to go.
And you can see how I've done that down in the, in the file there.
I have everything's pretty well labeled.
I would read it out to you, but trust me in the podcast, this would do no one any benefits.
So you have to actually see it.
Other good things that I've done with this that I took out of the, the version that's
on GitHub, but I remove this from that version.
But if you do things like SSH, right, in SSH, you can use an SSH config, which will allow
you to operate with servers, almost like with DNS, right?
So instead of typing in the server IP address, you could just type in a short name to get
to that server, you know, a human readable name.
Well, when you use ST, SFTP, because they recommend you not using, was it called a SCP anymore?
Because it's insecure.
So with SFTP, which is going to be operating under the same port as SSH, but it's, I don't
it's not governed by the SSH config, or at least I don't think it is, I need to actually
check on that.
It'd be a good show.
Y'all looking at that.
Anywho, in my input RC, I go ahead and add a macro down to my insert section, where my
macro will start off with semicolon.
So I do semicolon plus a quick little, you know, a short name, and it'll automatically
pre-fill the input with the SFTP space server that I'm about to SFTP into.
So for example, if you want to know what I'm talking about, SFTPing into HPR server,
right?
You guys know what an IP address looks like.
Was it four octets, whatever.
Yeah, we're not going to type all of that in, or try and remember it.
So I'm just going to set a macro down in here that goes colon HPR, or excuse me, semicolon
HPR.
So now at the command line, in insert mode, if I just type that in semicolon HPR, it will
replace that line with the SFTP proper syntax for, you know, getting into that HPR server.
And the reason why we do this is because, you know, we want to be able to do it correct
every single time, rather than, you know, having those human errors where you sometimes
type the wrong letter or wrong number, rather because it's an IP address or whatever.
So yeah, you just eliminating human error, giving something as short, easily remembered,
reproducible, and you can have as many of them as you want.
And you can do them for other things too.
I have others in here for doing nice and re-nice, as well as find, when I'm using find
at the command line, I always forget how to use find, because I don't use as much.
So rather than going back to my notes or, or hopping into the main page or whatever,
I have a, you know, a couple of find things that I use.
So I'll need left one in the example here.
But yeah, you just put a quick little macro for the things that you like to use right there
at the command line in there and about a boom, about a binger, good to go.
So just keep in mind, if you're going to set one up, remember to order, once you get
into that F statement, you start setting things up, don't start mixing and matching your
command based parameters with your insert based parameters.
You want to have like clear division command at the top, insert at the bottom or whatever,
you know, however you set it up, you want that to be clear.
And although I have not tried, I believe you can have multiple F statements, one for
a V and one for E max.
Again, I have not tried and I don't plan on because I just need to buy ones.
So thank you Dave Morris for giving us these wonderful shows.
I'm very grateful for the HPR community and all of the wisdom that everyone decides to
come here and share.
And I hope you guys will contribute more.
So if you've got a wonderful way to use the new Readline, let your entry be part five.
I'll see you guys in the next episode.
You have been listening to Hacker Public Radio at Hacker Public Radio does work.
Today's show was contributed by a HPR listener like yourself.
If you ever thought of recording podcasts, click on our contribute link to find out how
easy it really is.
Hosting for HPR has been kindly provided by an onsthost.com, the internet archive and
rsings.net.
On this advice status, today's show is released under Creative Commons, Attribution 4.0 International
License.
