I would like to configure bash so that when I execute command (preferably from a list of commands, not any command) without an argument, it takes the argument of previous command.So, for example I type emacs ~/.bashrc, then when I enter source, bash executes source ~/.bashrc. I know it's possible but I don't know where to look for such options.
Configure bash to execute command with last argument when no argument was provided
bash;command line;configuration;command substitution
You can press Space then Meta+. before pressing Enter. This has the advantage that you can use it even with commands that make sense when applied to no argument. For source, use . to type less.If you're old-school, you can use !^ instead to recall the first argument from the previous command, or !$ to recall the last argument, or !* to recall all of them (except the command name).You can get exactly the behavior you describe by writing functions that wrap around each command. The last argument from the previous command is available in the special parameter $_.make_wrapper_to_recall_last_argument () {  for f do eval <<EOF; donefunction $f {  if [ \$# -eq 0 ]; then set -- \$_; fi  command $f \$@}EOF}make_wrapper_to_recall_last_argument source .