[repost]How to corrects your previous Linux/Unix command with thefuck app
Let us face it we all make mistakes at the command line. Typos? Wrong options? Forget to add sudo? The list goes on. There is a neat little app called thefuck which corrects your previous Linux and Unix command line mistakes.
1. Installation
You need python version 2.7+ or 3.3+ along with pip and python-dev. Installation is super easy:
1-1. macoS installation
Open the terminal app and type the following command:
$ brew install thefuck
Sample outputs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
==> Installing dependencies for thefuck: sqlite ==> Installing thefuck dependency: sqlite ==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.20.1.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring sqlite-3.20.1.sierra.bottle.tar.gz ==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local, because macOS provides an older sqlite3. If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/sqlite/lib CPPFLAGS: -I/usr/local/opt/sqlite/include For pkg-config to find this software you may need to set: PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig ==> Summary ? /usr/local/Cellar/sqlite/3.20.1: 11 files, 3.0MB ==> Installing thefuck ==> Downloading https://homebrew.bintray.com/bottles/thefuck-3.23.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring thefuck-3.23.sierra.bottle.tar.gz ==> Caveats Add the following to your .bash_profile, .bashrc or .zshrc: eval "$(thefuck --alias)" For other shells, check https://github.com/nvbn/thefuck/wiki/Shell-aliases ==> Summary ? /usr/local/Cellar/thefuck/3.23: 711 files, 6.2MB |
1-2. Debian/Ubuntu Linux installation
Use the apt command/apt-get command as follows:
$ sudo apt-get update
$ sudo apt-get install python3-dev python3-pip
$ sudo pip3 install thefuck
1-3. Linux/Unix installation
On other system try:
$ pip install thefuck
2. Configuration
Edit your shell config file such as ~/.bash_profile/~/.bashrc/~/.zshrc and append the following config:
echo 'eval $(thefuck --alias)' >> ~/.bashrc
Reload the changes or restart the terminal app/shell:
$ source ~/.bashrc
3. How do I use it?
Simple. Whenever you made a mistake or typo, just type the fuck command. For example:
$ apt-get install nginx
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
To add sudo before the apt-get command:
$ fuck
sudo apt-get install nginx [enter/↑/↓/ctrl+c]
[sudo] password for vivek:
Reading package lists... Done
...
.....
..
Here are some more commands from my macos powered laptop:
![Gif. 01: fuck command in action](http://www.mobabel.net/wp-content/uploads/2018/09/15/demo-thefuck-command_161139.gif)
For more info see source code at: Magnificent app which corrects your previous console command.
4. A note about using bash !!
If you can’t install 3rd party tool or do not want to use this tool. Try !! syntax to run the entire previous command:
$ sudo $$
For example:
$ apt-get install vim
# Oh nooo, let us called above command with sudo
$ sudo !!
Let us say you run the following command instead of ls -l bar
$ ls -l foo
To correct it run:
^foo^bar
OR
!:s/foo/bar
Use it with vim if you want to write file when forgot to add sudo before and getting permission errors:
:w !sudo tee %
See bash man page for more info:
$ man bash
[source] How to corrects your previous Linux/Unix command with thefuck app