
The Fuck – Correct your previous console command - nvbn
https://github.com/nvbn/thefuck
======
csandreasen
Cool idea. For those systems where you don't have the option of adding a 3rd
party tool, it's probably worth knowing some of the standard bash shortcuts.
The easy to remember ones are:

    
    
      !^ - the first argument from the previous command
      !$ - the last argument from the previous command
      !* - all of the arguments from the previous command
      !! - the entire previous command
    

For example:

    
    
      $ apt-get install foo
      # Crap
      $ sudo !!

~~~
ferrari8608
I've been using "sudo !!" (which I pronounce as sudo bangbang in my head) for
a while now, mostly with vim for editing stuff in /etc. It's very nifty.

Another nifty tool is vi editing mode. You run "set -o vi", and now your shell
takes vi modal editing commands. That along with Ctrl-r for reverse history
search has made life in the shell so much easier. Bash has a ton of little
stuff like that built in. Zsh has a few more.

~~~
dogecoinbase
Probably my biggest overall timesaver has been:

    
    
       :w !sudo tee %
    

If you neglected to sudo before making your changes.

~~~
mattikus
I've had this in my vimrc for years:

    
    
       " Let :w!! gain sudo privileges without closing and reopening vim
       cmap w!! w !sudo tee % >/dev/null

------
c0achmcguirk
An issue that popped up for a user, kind of funny:

[https://github.com/nvbn/thefuck/issues/1](https://github.com/nvbn/thefuck/issues/1)

    
    
      who@where:~$ fuck
      No fuck given
      who@where:~$ fuck
      fsck from util-linux 2.20.1
      e2fsck 1.42.9 (4-Feb-2014)
      /dev/sda6 is mounted.
    
      WARNING!!!  The filesystem is mounted. If you continue 
      you ***WILL*** cause ***SEVERE*** filesystem damage.
    
      Do you really want to continue<n>? no 
      check aborted.

~~~
jnetterf
If you're less adventurous, and use fish/tmux, you could try something like:

    
    
      # config.fish
      function fuck
          thefuck (history | head -n1) | tmux load-buffer -
          tmux paste-buffer -s \0
      end
    

This will paste the command The Fuck suggests without a return so you can
audit the corrected command before running it.

------
manojlds
Git already has a config to do this:

    
    
      help.autocorrect
    
      Automatically correct and execute mistyped commands after waiting for the given number of  deciseconds (0.1 sec). 
    
      If more than one command can be deduced from the entered text, nothing will be executed. If the value of this option is negative, the corrected command will be executed immediately.
    
      If the value is 0 - the command will be just shown but not executed. This is the default.
    

[http://git-scm.com/docs/git-config](http://git-scm.com/docs/git-config)

~~~
nvbn
Cool, didn't know about that before.

------
hurin
Not being 100% sure which command this will correct to is dangerous. Also the
need for this is largely negated by a shell with autosuggestions.

~~~
JadeNB
> Not being 100% sure which command this will correct to is dangerous.

And yet the concept of the invocation `fuck --dry-run` is surely unappealing.
:-)

~~~
chaosfox
I think dry-run should be the default. Then if you really want to run it
without checking the command first you could do:

    
    
        fuck --without-condom

or maybe

    
    
        fuck --iamfeelinglucky

~~~
fnordfnordfnord
\--bareback?

------
fifthecho
99 times out of 100, my issue is forgetting to sudo a command, so I just have
'alias fuck="sudo !!"' in my ~/.bash_profile

~~~
seletskiy
Check it out:
[https://github.com/seletskiy/dotfiles/blob/master/.zsh/alias...](https://github.com/seletskiy/dotfiles/blob/master/.zsh/aliases.sh#L102)

Far more easier to press CTRL-T than type `fuck` every time.

------
dbbolton
Zsh's completion system handles most of those examples if enabled:

[http://zsh.sourceforge.net/Guide/zshguide06.html#l162](http://zsh.sourceforge.net/Guide/zshguide06.html#l162)

[http://zsh.sourceforge.net/Doc/Release/Shell-
Grammar.html](http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html)

[http://zsh.sourceforge.net/Doc/Release/Expansion.html](http://zsh.sourceforge.net/Doc/Release/Expansion.html)

It can actually be integrated into history expansion, used at will, configured
with a custom prompt, told to ignore certain words and files that annoy you,
etc. But if you try to search for "zsh correction", most posts are related to
disabling it entirely.

------
camhenlin
I think it's a funny little app. I could see it being kind of useful for the
author but I think I would personally have trouble using an app that I don't
actually know what it's going to do 100%. I think that you could mitigate this
a bit by putting the list of commands it corrects right at the top of the
readme.

I think most of us have probably been at the point where we were typing
something like "I hate you, you god damn computer!" into the terminal or text
editor. I see this as a moderately elegant helper in those situations

~~~
shampine
Check out the only issue open:
[https://github.com/nvbn/thefuck/issues/1](https://github.com/nvbn/thefuck/issues/1)

I like it, but I have to know every command it modifies/checks, I cannot run a
blackbox command and hope.

~~~
nacs
That issue has an alias you can use:

    
    
        I just added an additional alias for testing. 
        It simply outputs the command fuck would execute:
    
        alias tryfuck='thefuck $(fc -ln -1)'

------
mormegil
"In one notorious incident, Warren added a DWIM feature to the command
interpreter used at Xerox PARC. One day another hacker there typed delete _$
to free up some disk space. (The editor there named backup files by appending
$ to the original file name, so he was trying to delete any backup files left
over from old editing sessions.) It happened that there weren 't any editor
backup files, so DWIM helpfully reported _$ not found, assuming you meant
'delete *'." See
[http://www.catb.org/jargon/html/D/DWIM.html](http://www.catb.org/jargon/html/D/DWIM.html)
and also
[https://en.wikipedia.org/wiki/DWIM](https://en.wikipedia.org/wiki/DWIM)

------
ChristianBundy
I wrote a similar Sudo History Invocation Tool to do this:
[https://github.com/christianbundy/shit](https://github.com/christianbundy/shit)

------
dheera
What I really want is a wrapper for sudo. Whenever I use sudo, if type the
password correctly it works instantly; if I mistype the password, it delays
for 2 seconds before asking again. Often it's faster to Ctrl+C UP ENTER than
to wait for that annoying 2 seconds. So it would be nice if a wrapper existed
to see if sudo gives access within 0.1 seconds, and if it doesn't, assume the
password was wrong, kill the sudo process and launch the command again.
Automate the Ctrl+C UP ENTER.

~~~
juliansimioni
I suspect the delay in sudo is configurable: it's not there because sudo is
actually doing any work checking your password, it's there to prevent
attackers from trying many many combinations of passwords quickly.

If you care about that protection, then you don't want to circumvent it, but
in the equally reasonable case where you don't care, then you can probably
just make sudo faster.

~~~
dlgeek
It actually comes from PAM - man pam_faildelay

------
aviraldg
.. ten seconds until there's outrage against the name and a campaign to have
it cleaned up. (see: Karma)

Very useful though.

------
bane
I've started to wonder why we've never seen a more IDE-like autocomplete in
consoles. I mean, why do I have to use man pages and all sorts of reference
guides to remember the parameters for find or grep or whatever, or the order
of commands for whatever?

There really needs to be better communication between software and the
environment it's running in.

~~~
Symmetry
I feel like fish gets part of the way there by grabbing stuff from the man
pages and displaying descriptions in tab-complete options. But we're still a
ways from the anti-Mac user interface[1]. Unless maybe you count Google's
search bar.

[1][http://www.nngroup.com/articles/anti-mac-
interface/](http://www.nngroup.com/articles/anti-mac-interface/)

------
kbenson
Projects like this always make me think the developer's imagination has
drastically failed them with respect to the scope of negative consequences
that may result from using their tool.

~~~
tonyhb
Projects like this always make me think the developer's imagination is great
and they must at least be intelligent enough to criticise their work (with
humour).

------
jacob9706
Added the `fuck --dry` option from the comments below, waiting for it to be
merged.

All it does is print the command to run and prompts for [Y/n].

------
kylecesmat
Issue #1 is classic.

Running 'Fuck' twice attempts to evaluate the previous 'Fuck'\- and returns
'fsck' \- which tries to forcefully check your mounted drive.

I wouldn't trust this app for practical use.

~~~
babuskov
You can surely trust that it will 'fuck' stuff up at some point.

------
cevaris
Got to love
[https://github.com/nvbn/thefuck/issues/5](https://github.com/nvbn/thefuck/issues/5)

------
whizzkid
I think i will continue using the Fish shell feature instead. It has this
awesome feature of autocompleting your command with the bash history of yours.

It is safe because it will autocomplete a command that you wrote before.

Another cool thing with it is that, it will list the commands that you can run
after entering a word. It does this by reading the man page of the command you
write.

brew <Tab> will list the brew commands for you to use with its explanations.

------
abc_lisper
I will not let my coworkers see me typing expletives into terminal; much less
if it is a woman.

It is a nice idea, though. Will use it if it's called auto-correct or
something.

~~~
danellis
I'm not sure what difference you think gender makes, unless you think women
are delicate flowers that must be sheltered from bad language, but I do agree
that it would be better named something more office friendly. I'd suggest
'argh', 'grr' or 'gah'.

~~~
genderbar
Profanity is (deliberately) uncomfortable to people who are not part of your
in-group. Women are more likely to be/feel excluded from in-groups in
technology workplaces.

~~~
lesmiserable
Profanity is a wonderful spice of life, it is deliberately uncomfortable to
people who take things way too seriously.

~~~
genderbar
Get back to me after someone you don't like or don't trust throws you some of
that spice.

~~~
lesmiserable
you mean like being in any public space? I only get to control how I react.

------
bcheung
The birth of a new metric:

alias WTFs="history | grep fuck | wc -l"

------
zenojevski
Here's an equivalent "alias" for the fish shell:

    
    
        function fuck
            eval (thefuck (history | head -n1))
        end

~~~
nvbn
Thanks, added to readme.

------
jryan49
Made an Arch AUR package. First time making VCS package. Might be terrible.

[https://aur.archlinux.org/packages/thefuck-
git/](https://aur.archlinux.org/packages/thefuck-git/)

------
pervycreeper
I'm not quite sure I understand why this is any better than using the up
arrow.

I thought the cardinal rule of sysadmins was "think before you press enter".
This seems to discourage that mindset.

------
agumonkey
C-o
[https://www.google.com/search?q=readline+operate+and+get+nex...](https://www.google.com/search?q=readline+operate+and+get+next)

------
_ZeD_
it's only me to just tap "up" and edit the command?

------
aerovistae
I just keep getting "No host name on command line, aborting."

Also was asked to install "suck." Not sure why / what that is.

~~~
fapjacks
One of the issues on the Github reveals that at least one user ended up
running "fsck" after typing "fuck" twice. :)

------
mayneack
Mildly related: [http://bropages.org/](http://bropages.org/)

------
nullc
I wonder if the name came from some version of this pithy one-liner:

To err is human, to really fuck things up requires a computer.

------
LfLxfxxLxfxx
I was expecting to see in the examples:

    
    
      $ wrongcommand
      error
      $ fcuk
      command not found
      $ fuck

~~~
abc_lisper
This.

------
anonbanker
I've created perl scripts for fuck, shit, and goddamnit. they merely echo an
array slice to the terminal, from a list of about 30 phrases. had 'em for
about 15 years now.

    
    
      <root@ButtPirate>$ fuck
      I hope this computer dies of ass cancer.
    

always makes me feel a little better about life. this app might be more
effective, though.

------
sgtpep
Out of the box bash trick:

    
    
       export EDITOR=vim
       C-p (or Up)
       C-x C-e

------
cfrs
Someone should fork fish and create fuckfish: a shell that fucks automatically

------
alienth
For those wanting something safer but similar, see the `fc` shell function.

------
scottmwinters
yea, lots of us use shells with suggestive text...that doesn't make this less
amusing. Now if only someone would make rules for my osx terminal, thatd be
great

------
vinceyuan
Super interesting. I LOLed. But I will not install it.

------
bharad
Also, fix command might help

$ fc

------
joeminichino
Funny, when i make a mistake i exclaim "what the!" instead of "the fuck".
"wot" is my suggestion for a better name.

~~~
rjuyal
What the Exclamation mark.

------
soheil
I praise you for giving us the fuck!

------
foxhop
Unix 'fc' or fix command

------
JulianMorrison
$ rm -rf / oops

permission denied

$ fuck

sudo rm -rf --no-preserve-root / oops

$ _

------
alfasin
alias fuck='sudo $(history -p \\!\\!)'

------
aabajian
I'm going to go out on a limb here and suggest that you rename it "The Fix."
Then you could type "fixit" or just "fix".

~~~
cpncrunch
Yes, using the word "fuck" for this just strikes me as a bit immature.

~~~
icebraining
American prudishness. There's nothing immature in swearing in and of itself.

~~~
urda
> American prudishness

Sounds like you need a review of:
[https://news.ycombinator.com/newsguidelines.html](https://news.ycombinator.com/newsguidelines.html)

Or perhaps just some common decency ? If you want a tool / platform to take
off, using the word 'fuck' is not the way to go.

~~~
lectrick
I too read those guidelines in their entirety and there is nothing there at
all about the poignant use of so-called "swear words."

Also:

[http://thefuckingweather.com/](http://thefuckingweather.com/)

[http://www.whatthefuckshouldimakefordinner.com/](http://www.whatthefuckshouldimakefordinner.com/)

etc.

------
brento
This looks very helpful ... however, could we get a PG version like "The
Crap"?

~~~
sneak
People are not materially harmed by short strings, so no.

~~~
benmcnelly
What if they were objects?

------
keslag
Amusing, but I would prefer something that would be able to automatically know
what I was meaning to do and just do it without having to be vulgar.

~~~
gknoy
Agreed. They could even sanitize it a little bit as 'wtf' or 'oops'.

~~~
sneak
WTF means the same thing. That is no less vulgar.

~~~
dragonwriter
> WTF means the same thing. That is no less vulgar.

Vulgarity of expressions is not a function only of what the expression means,
but of the acceptability of the expression itself in various social contexts.
WTF is, generally, acceptable as not excessively vulgar in social contexts
where expanding the last letter of the initialism into its referent would not
be, but the reverse isn't true; WTF is pretty close, therefore, to strictly
less vulgar.

This may not seem rational, but then the entire concept of vulgarity is
irrational.

~~~
Crito
> _" WTF is, generally, acceptable as not excessively vulgar in social
> contexts"_

Which social contexts? Social contexts where people don't know what "WTF"
expands to? It's not even a "minced oath".

~~~
frenchy
"WTF" is less vulgar than "fuck" for roughly the same reason that "the f-word"
is less vulgar than "fuck".

~~~
Crito
I don't buy it.

 _" The f-word"_ is used exclusively by people being descriptive. Nobody says
_" So I was f-wording my spouse..."_ or stubs their toe and exclaims _" oh
f-word!"_. It is used when people are reporting what other people said. That
is why it is considered less offensive; it is never properly used.

It signals to the easily offended, _" I want to convey this information to
you, but I am deliberately mangling words so that you know I too disapprove of
the terrible word that was unfortunately used by somebody else."_

 _" WTF"_ isn't used that way. When people say it, they are _using_ it, not
describing somebody's usage. There is zero implication of an apology or
empathy with the audience's word-phobia.

------
nine_k
I'd not use this.

It's basically a negative, aggressive emotional response, exactly a thing I'd
rather not experience while working.

A failure due to not enough privileges might be a signal to rethink what you
are doing; a mindless prepending of `sudo` is dangerous. Why not `su root`
then?

Also, there was that screnshot of `sudo wget` as a response to a 403 error.
This is exactly why you should re-examine a failed command instead of swearing
around.

~~~
Karunamon
I would, because a lot of commands could be improved by a "do what I mean"
option.

GNU find is smart enough to tell me that I've placed one of the flags or the
find string in the wrong place, but not smart enough to correct the fucking
error and do what I meant in the first place. (It knows, it just won't do it.)

"apt-get/yum install" is unusable by anyone but root. Why do I need to waste
time re-keying the command? This is annoying enough that I've aliased it[1] on
every machine I have access to.

I'd be willing to bet the collective man hours wasted on these worthless "you
did it wrong, here's how you did it wrong, now go do it right" type messages,
expands well into the decades.

[1]:
[https://github.com/Karunamon/dotfiles/blob/1174bbaee047107ea...](https://github.com/Karunamon/dotfiles/blob/1174bbaee047107ea0dc87b1e4286a4445713bb8/.bash_profile_linux)

~~~
nine_k
"Do what I mean" is great as long is what you mean is what the computer
infers. As everyone who wrote Perl or used MS Word knows, this is not always
the case. And when it is not, it's often super annoying.

How often do you run apt-get install? I bet it's not even a daily routine. (If
it is, you should have already automated it.) OTOH if you run chmod or chown
and it _suddenly_ requires root privileges, it's a good idea to think a bit; a
disaster may be around the corner.

There are different mentalities; some crave for unconstrained aerobatics while
others keep reminding to wear a parachute. I wish you all the luck, but I
won't wish you be my SRE.

