3 ms·
Remiss for not mentioning "rlwrap": https://github.com/hanslub42/rlwrap https://github.com/hanslub42/rlwrap ...basically "readline in a can" that you can use t
by ramses0 2y ago
Remiss for not mentioning "rlwrap": https://github.com/hanslub42/rlwrap https://github.com/hanslub42/rlwrap
...basically "readline in a can" that you can use to improve text input of other programs.
I forget if it was RMS or ESR that really wanted to hold "readline" away from corporations, so it's licensed as GPLv3 (not v2), and he explicitly wanted it to _not_ be LGPL (ie: embeddable).
My crazy readline/bash tip is `ESC, .` (or maybe `alt+.`, I'm not 100% sure, random search result here: https://gist.github.com/tuxfight3r/60051ac67c5f0445efee https://gist.github.com/tuxfight3r/60051ac67c5f0445efee ). Basically it up-arrows through the last "word" of previous commands, adding it to the current command.
Example:
mkdir foo
cd `esc, .` => cd foo
vim bar.txt
cp `esc, .` baz.txt => cp bar.txt baz.txt
It's crucial in that it reduces the number of keystrokes, and avoids typing errors completely, as you're "recalling" something rather than re-typing.
I'm also in the same boat as the author in that `set -o vi` doesn't quite do it for me (although I consider myself an expert in vi). What I tend to do instead is:
C-a # <cr> => go to the beginning of the line and insert a comment char
fc => "fix command", see "help fc" (it's a built-in)
...basically it invokes: `$EDITOR "$( history | tail -1 )"` and whatever you save/quit will get executed as a command.
This lets me intentionally "damage" a command, but then get into `vim` to "fix it up" (eg: `dw, cw, df/, etc...`). Remove the comment from the beginning of the line to execute it, or keep it there to take the command back "out" of `vim` so you can keep building it up.
- wild_egg 2y agoI've always used !$ to get the last word of the previous command like so: mkdir -p foo/bar cd !$ # => cd foo/bar I suppose the advantage of `ESC, .` is universality since it'd work inside any readline prompt? Not sure how frequently I actually need to do that outside of bash but going to keep it back of mind in case I do, thanks
- ramses0 2y agoI like the interactive nature of esc-., you can keep "up arrowing", to a value a few commands ago and crucially: edit the value. (add/remove `tgz`, etc)
- fragmede 2y ago`alt .` :)
- loulouxiv 2y agoC-x C-e opens an editor with the currently edited command