3 ms·
Yup, readline's yank-last-arg command Alt-. or Alt-_ (see https://www.gnu.org/software/bash/manual/html_node/Commands-For-History.html#Commands-For-History http
by mrb 7y ago
Yup, readline's yank-last-arg command Alt-. or Alt-_ (see https://www.gnu.org/software/bash/manual/html_node/Commands-For-History.html#Commands-For-History https://www.gnu.org/software/bash/manual/html_node/Commands-...) is the best off-the-shelf solution that still gives the ability to interactively edit the filename. To minimize the total number of key strokes I would suggest:
mv foo.txt
↑
Alt-.
That is: intentionally run mv with only one argument (the command fails but is recorded in the history), Up arrow to recall the last command, and Alt-dot (pastes the last argument).
This is literally replacing an entire shell script with two key strokes (Up, Alt-.)
- sigjuice 7y agoWhat version of bash do you use? I can't seem to get this to work with mine. For me, Alt-. gets the last argument of the penultimate command. $ echo $BASH_VERSION 5.0.11(1)-release $ mv foo.txt mv: missing destination file operand after 'foo.txt' Try 'mv --help' for more information. $ mv foo.txt $BASH_VERSION # Alt-. pasted $BASH_VERSION instead of foo.txt