by hnlmorg · 2y ago · 0 comments
grep “thing I want” !$
Bash (and similar) will replace !$ with the last parameter of the previous command.This is a trick I’ve used lots when wanting to perform a non-piping operation on a command I’ve ‘cat’ed (eg ‘rm -v !$’)
I’d never criticise anyone for “useless” use of ‘cat’ though. If the fork() overhead was really that critical then it wouldn’t be a shell command to begin with.
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.
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
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 :)
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. cat filename.txt
grep "what I want" $_
expands "$_" to "filename.txt"Then I can look at it before hitting return
useful shorthand
> sudo !!
for example.
Again, bash specific.