bash && zsh: referencing / repeating a previous command line *argument* while still crafting the same line
Let's say I am entering some complex command that repeats one of the command line arguments, or some variation of one of the arguments, and let's say I'm dealing with very long and complex command line arguments.
It would be one of the below patterns, where "foo"
is the very long and cumbersome argument and "foo2"
is a variation of it where the "2" character is appended.
$ ./binary "foo" "foo"
[...]
# OR
$ ./binary "foo" "foo2"
[...]
# OR
$ ./binary -x "foo" -y "foo"
[...]
# OR
$ ./binary -x "foo" -y "foo2"
[...]
Is there some way to have bash
/ zsh
auto complete the second instance of "foo"
without having to manually copy & paste it?
Basically, I'm looking for something like the below, but in the same command line instead of referencing a previous command line.
$ echo one two three > /dev/null && echo !:2 !{:2}2
two two2
Possible (suboptimal) solution:
# not ideal because it requires me to realize in advance
# that I will have to repeat "foo" on the same line
$ (FOO="foo"; ./binary "${FOO}" "${FOO}2")