For example, say you want to run "chown root:root foo". Alt-. gets you "foo", not the entire command, and "sudo foo" isn't useful,and in some cases could do something else entirely. For example, with the command "service foo restart", you would end up with "sudo restart" (which while it doesn't execute right away, is exactly what I'm guarding against).
Unlike Emacs, M-1 etc. can't be typed as C-u 1 etc.
$ yum install bash-completion
Error: This command has to be run under the root user.
$ sudo <Alt-.>
$ sudo bash-completionBut I'm an epic coward that even looks both to the left and the right before crossing a street. :-)
#!/bin/bash
echo -n "Are you SURE you dumbass? [N/y] " >/dev/stderr
read -n 1
if [ "$REPLY" = "y" ]; then
echo >/dev/stderr
exec /usr/bin/sudo "$@"
else
exec echo -e "\n:-)" >/dev/stderr
fi
That way even if I already typed my password, I systematically get asked if I'm sure I want to execute the command.I think I'm pretty proficient as a basher, but I also never use the bang, nor do I use the 'history' bit. Didn't know about alt-. tho, that's handy.
I could toss 'control-k' for 'delete to end of line' that hasn't been mentioned. And of course control-P/N for previous/next commands (or arrows obviously).