3 ms·
Even easier, press alt+. (fewer keystrokes too! cli golf is fun), it'll copy-and-paste the last parameter from the previous command. If you press . multiple tim
by mmh0000 3y ago
Even easier, press alt+. (fewer keystrokes too! cli golf is fun), it'll copy-and-paste the last parameter from the previous command. If you press . multiple times it'll go further back into your history.
- bee_rider 3y agoOften the shortcuts that people point out in these threads are too niche for me to remember, but that seems like a pretty great one, I’ll try to remember it.
- imp0cat 3y agoalt + . is easy to remember, but did you know you there is a way to recall any argument from the previous command in bash? Press Escape, then the number of the argument from the previous command, confirm with Ctrl+Alt+Y. Example: > command arg1 arg2 arg3 Escape, 1, Ctrl+Alt+Y gives you arg1.
- penguin_booze 3y agoalt + <number> + alt + . should do the same thing. No need for ctrl+alt+y, is there?
- smackeyacky 3y agoNot sure that would work everywhere but !$ definitely does for retrieving the last arg of the last command. 40 years of muscle memory right there
- bierjunge 3y agoNobody mentions $_ ? It gives you the last argument used, so: cat filename.txt grep "what I want" $_ expands "$_" to "filename.txt"
- penguin_booze 3y agoAlt + . is a readline binding, so that's available wherever GNU readline is used. Immediate examples that come to mind are Python PDB shell and GDB.
- cassepipe 3y agoAnd thus you get vim modes there too much if you set your .inputrc for it !
- 6c696e7578 3y agoAs I tend to live with set -o vi, [esc] _ gets the same. I hardly ever remember to set: bind '"\e."':yank-last-arg So [esc] _ does it on systems where I haven't customised my environment. A major drawback though is it doesn't go through history like alt . does. However, when 'set -o vi' is enabled you can easily go through history and edit with familiar vi keystrokes, or press 'fc' and fix the previous command in EDITOR, or 'v' to edit the current command in EDITOR.
- cassepipe 3y agoCommand line vi modes are my bread and butter I think you meant 'vv' and I wonder if it's not something that's set up by oh-my-zsh ? It's great though
- 6c696e7578 3y ago'v' will start the visual editor. 'fc' will edit the previous command. Both invoke EDITOR in bash's vi readline command mode. I wasn't aware that bash and zsh did it differently, I assumed they'd both use the same readline - now I'm aware there's more to understand about it :)
- cassepipe 3y agoHa my bad I assumed zsh because I saw the `bind` command being used. I did not know that it was also in bash I find that zsh's mode is actually better than readline's For example it can handle visual mode which is why the same function is `vv` and not just `v` Zsh can handle text objects too, very useful to be able to ci" for example Fish's can too and is quite good IIRC Too bad the `v` command does not work in gdb so it seems it's more of a bash thing than a readline thing Relevant : https://superuser.com/questions/1543120/make-readline-edit-input-command-in-external-editor-similar-behavior-as-edit-a https://superuser.com/questions/1543120/make-readline-edit-i...