There are a few ways to rectify specific issues with your last command like
sudo !!. But how about a utility that could correct wrong commands or typos as well? Before proceeding further, I must state that I am not responsible for the NSFW name of the tool and would strongly suggest the author changes it to something civil. The Fuck is a useful python tool that can correct your last command and run it. It can work with bash, zsh or fish shells.
The utility tries to match rule for the last command, create a new command using matched rule and run it. The default enabled rules are git_no_command, git_push, no_command and sudo. However, it doesn’t stop there. You can add your custom rules. Sample rules can be found under ~/.thefuck/rules directory.
To install the utility:
$ sudo pip install thefuck
Add alias (as fix) in .bashrc or .zshrc:
alias fix='$(thefuck $(fc -ln -1))'
Or for fish shell in config.fish:
function fix eval (thefuck (history | head -n1)) end
$ apt-get install vim error ... $ fix sudo apt-get install vim ... $ puthon error ... $ fix python $ git push error ... $ fix git push --set-upstream origin master
On GitHub: The Fuck