First, note that !:0
is not the command in the last line of history. It's the first word. So if you run A=B some-command arg1
, !:0
will be A=B
.
That said, since you mention Alt., which is:
yank-last-arg (M-. or M-_)
Insert last argument to the previous command (the last word of
the previous history entry). With a numeric argument, behave exactly
like yank-nth-arg
.[...]
There's the aforementioned yank-nth-arg
:
Insert the first argument to the previous command (usually the second
word on the previous line) at point. With an argument n, insert the
nth word from the previous command (the words in the previous command
begin with word 0).
So you could do Alt0 AltCtrly, or, since yank-last-arg
behaves "exactly like yank-nth-arg
" with an argument, Alt0 Alt..
You can make a binding for this, but it's a bit roundabout - apparently readline doesn't have a mechanism to bind to a command while specifying an argument. You have to bind to a key sequence which first imitates sequence for an argument and then then the sequence for an existing binding, so you could do:
bind '"\e,": "\e0\e."'
And press Alt, to get the first word.
pr
is an existing Unix command, you should pick some other name for your alias or function to avoid breakage in your code and/or other tools you use now or in future that might be callingpr
.