Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Fuck – An app which corrects your previous console command (github.com/nvbn)
287 points by claroscuro on April 17, 2017 | hide | past | favorite | 103 comments


  [~user/]$ rm -rf /
  rm: it is dangerous to operate recursively on `/'
  rm: use --no-preserve-root to override this failsafe
  [~user/]$ fuck
  sudo rm -rf --no-preserve-root /
fuck!


That was my first thought, although it looks like they were responsible enough to make you hit return to confirm that you want to run the command


Rule for this behavior disabled by default, but you can enable it. Also you can disable confirmation or use `fuck -y` for more fun.


I feel like they missed an opportunity to use 'fuck yeah' as the automatic override.


    alias just=sudo
    just fuck -me -up


This is Art. Thank you for doing Art on HN.


I like how you named and styled the command after how many terminal users actually approach these situations.

1. Hurriedly type something to solve a pressing problem. It doesn't work but tells you enough the fix should be obvious to a machine.

2. Mutter or shout "Fuck!" in head depending on how obvious problem was, how often it repeats, or just how long it takes to redo it.

3. Perform the correct action.

Your model is like the Underwear Gnomes model for problem-solving applied to terminals. They always missing step 2. Except, on step 2, you just "fuck" to get profit... err, you get to finish at Step 2 with one word. Finish faster with this technique to move on to next job in workflow.


Of course, the drawback is that the machine doesn't really know what you intended without more context than a single command line. Often it can make a good guess, but not always and sometimes it'll guess wrong, perhaps disastrously so.


Well, it's guessing the intent of a user on command line and trying to fix their problem automatically. I don't expect perfection so much as it working well enough in common situations.


But it asks for confirmation and almost always suggests more than one option. Although it isn't smart enough to remember what you chose and suggest this variant in future.


Why not introduce some sort of AI to it and get it to understand more what one wants to do?


I use this regularly, for everything ranging from the forgotten sudo (instead of running "sudo !!") to typos across the board.

But it does get me into interesting situations! Just the other day I was demo-ing something to my team + Director of Engg on the projector, and I ran an incorrect command, followed by "fuck" to fix it, leading to so many stares :P

Just as an FYI, you can change the prompt from fuck to something else by changing your .bashrc eg.:

    eval "$(thefuck-alias fixit)"
I'm not changing my alias though! ;)


funny!, next time i am demoing, i will try to do it, to show off obviously


I often set `alias fucking='sudo'`.

    >$ make me a sandwich
    permission denied
    >$ fucking make me a sandwich
    [or]
    >$ fucking !!


I have the same.

    # Because sometimes you gotta be harsh.
    alias fucking="sudo"
    
    # And sometimes you gotta be nice.
    alias please="sudo"


Works with my wife.



I see why you linked that.

My brain nearly double faulted from learning new things too fast. Great thread.


Hi. Thanks for catching the JS injection and shock site redirect bug. I fixed it.


Ah, good to hear. Sorry it happened.

Since https://news.ycombinator.com/item?id=14144814 got locked (which, to provide context for anyone else reading, is why this reply is here in this thread) maybe you could repost it now.

FWIW, this idea in and of itself is worth spending a bit of time on. The page itself is very... basic right now, and I wouldn't discount that this may be one major reason why nobody is taking the concept seriously.

Which makes sense: nobody knows what your areas of specialty and experience are, what you're capable of, and all they've got is this very barebones page. Noone knows what to suggest for you to do!!

Spending some time on the page design and specifying the kinds of things you're capable of - and, most importantly, the things you're most interested in - might just turn things around a fair bit.

Thanks for the ping :) and hopefully you see this.

I note you have not yet put any contact info on that page :P (Gmail happily forwards, and Outlook (which forwards too) also has aliases)

My email is in my profile FWIW. You could also drop your username on the page and tell people to "find your email on HN". That could be a good filter.


If you mistype fuck, does it properly recurse up the fuck chain?


    > fsck
    ERROR: volume / is mounted with write access. Re-run with (-l) to freeze volume.
    > fuck
    No fucks given


Another step towards the Anti-Mac user interface.

https://www.nngroup.com/articles/anti-mac-interface/


It's an interesting proposition. A highly abstracted, very high level, very modal multi-user system where users actually interact instead of being sandboxed.

Keep in mind that "anti-X" stuff tends to resemble the original "X", thus despite the antagonistic name, this is probably not as revolutionary as we will get.


What would be the Mac design principle way of doing this then? Would every command line tool then be an Anti-Mac user interface?


More or less helping move from 'direct manipulation' to delegation. It's not so much that this is moving away from any particular Mac principle so much as towards the sort of system outlined in that essay.


"Anti-Mac interface" doesn't seem to be pejorative in this context.


Would be nice to have some form of autocorrect directly in the shell, especially if it was aware of common programs and so could also autocorrect options. Obviously we could think of a few cases with destructive outcomes--but that doesn't make it a bad feature.

git stauts

I mean, git knows enough to ask me "Did you mean this? status".


Add this to gitconfig file. It will automatically run the correct command after displaying what it is after a delay.

The value is in 0.1s (centiseconds) of seconds. So 20 means 2 seconds.

[help]

autocorrect = 20

OR run git config --global help.autocorrect 20


Wouldn't those be deciseconds? Also wtf unit. Use Millis or seconds as a float. Yay Linus making sure that git only makes sense to wizards like him.


The Linux kernel seems to have a centisecond obsession too. Probably from way back when HZ was 100 and your computer woke up once every centiseecond to make sure it still had nothing to do.


I don't know. I'm confused as is. I really hate when people break:

1. Conventional units.

2. Don't follow the XDG basedir spec for config files.

3. Make inconsistent command line flags.

4. Don't allow control of color output using a flag thinking they are smarter than me.


Wow, great tip, thanks. One command down, hundreds to go.


I once set up a schedule where I would open the gitconfig manpage and read at least one section of the settings. My gitconfig file growed to over 200 lines then.

Quite a lot of stuff isn't very helpful in there though.


Besides this, I feel quite reliant on Ubuntu's "you don't have $CMD, but you would if you installed $PKG" suggestions (https://launchpad.net/ubuntu/+source/command-not-found).

A real autocorrect should probably know about all the systems I use, instead of just the one I'm actively using, and help me translate commands from syntax I "expect" to syntax that works for that system. (e.g. translating my zsh pipelines to bash pipelines; suggestion combinations of commands that can substitute for missing builtins; translating between old GNU tar/ps syntax and old BSD tar/ps syntax...)


> git stauts

I added that as an alias in my git config. Even though I usually just type git st (another alias I added), sometimes my fingers type all the letters out and still fuck it up.

Of course, as I'm sure many of you do, too, I've also got a bunch of even shorter bash aliases like gpp (git pull --rebase && git push)


This will definitely help some co workers who aren't CLI-savvy and always tell me their commands "didn't work".


You have the problem too? Everyone comes to me when the get a conflict because they don't read the part that says when you're done, do `git rebase --continue`


An oldie that has been passed around in various incarnations since the 2000s is an alias also called fuck which repeats the last command with sudo. Either coincidence or perhaps it could be where the inspiration for this project came from.

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


Didn't this appear on Hacker News years ago? I have been using it since and absolutely love it!


wow yeah, this is what, 2+ years old?


My favorite shell typo: dicker instead of docker. More funny if you speak German :)



Love it, have thought about it, but my one concern always is that it'll lead to a decrease in my typing skills instead of reinforcing good keying. But fuck, I just need to get stuff done sometimes.


Personally my typo rate has held pretty steady over the last decade, I don't think something like this would have any measurable effect on how well one types.

My concern would be that the extra keystroke to confirm would ingrain the skip confirm (fuck -y, or even just hitting enter before I'm prompted again) into my muscle memory, with potentially disastrous consequences (hence I've never installed this tool).


Is this any easier though than the using the carat style previous command substitution?

    ^bar^baz
Although I think the name might be more descriptive.


It does more then substitution

  $ git pull
  There is no tracking information for the current branch.
  Please specify which branch you want to rebase against.
  See git-pull(1) for details.

    git pull <remote> <branch>

  If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> test

  $ fuck
  git branch --set-upstream-to=origin/test test && git pull [enter/↑/↓/ctrl+c]


I don't understand how you think anything is easier than typing 'fuck' and have it identify and correct your mistake for you?


Lets see in order to use "fuck" I need to first install it and its dependencies. The caret substitution natively exists in the Bash shell.

Also I know that no matter what system I am on be it OS X or Linux the caret syntax is guaranteed to work.

I don't understand how you think anything can be easier than using the functionality that has existed in the Bash shell shell(or even C shell variants)since forever.


If that were how things worked, we'd never use any new technology. Obviously it is easier to pay a one-time up-front cost than to slog away inefficiently forever.


>"If that were how things worked, we'd never use any new technology"

Nice try. That's a straw man. This isn't new technology. Its simply replicating existing functionality.

>"Obviously it is easier to pay a one-time up-front cost than to slog away inefficiently forever"

Whats the average typo 1 character as in most of the demos for "Fuck"? So I can either type 2 carets and 4 letters for a total of 6 characters or I can type the 4 characters in the word "fuck", how is the former inefficient? Wow, what a slog. I can't imagine what I will do with all the time I will have left over after installing this"


Speaking of straw men, this program does more than simple typo substitution. The listed examples include prepending sudo and using git-suggested commands.


>"The listed examples include prepending sudo"

Which you can get by typing:

    sudo !!
and git completion is in contrib:

https://github.com/git/git/tree/master/contrib/completion

Not really a strawman is it?


Well, yes it is, because again, I was just giving examples. Look at the list under "how it works" in the readme, and there's plenty of items there that aren't simple substitution. It'd be a lot easier to just 'fuck' for most of those than have to mentally parse what you need to do to 'fix it'.


Yes for some use cases. On my keyboard setup it is significantly faster to type four common characters than to think about and type two ^ between substitutions.

^ substitution is more precise and I think it is an under appreciated tool, but I don't think that negates the usefulness of thefuck.


This is wonderful.


Every day:

$ git pish

$ fuck


For those who don't know, you can make git pish have the same effect as git push by creating an alias between pish and push. Useful to do for any misspellings you make more than once.

$ git config --global alias.pish push


Cannot for the life of me tell if this is a serious suggestion.


I've actually done this for a couple commands I screw up often enough -- I have this in my bashrc:

  alias dumbtypo="echo 'LEARN TO TYPE, MORON'"
  alias sl="dumbtypo; ls"
  alias rbuy="dumbtypo; ruby"
  alias pytohn="dumbtypo; python"
  alias brwe="dumbtypo; brew"
  alias arhcey="dumbtypo; archey"


I'm incredulous that 'pythong' is not in there.

I can't not-type it.


You ... type "python"? Not pyt[tab]?


I type pythong all the time, too.


I was worried I was the only one!


if you sudo apt install sl you will have more fun making that typo ;)


there are a couple things I typo frequently enough I've seriously considered it...


It is-- what is the perceived downside?


You have a giant list of common typos, making you a worse and worse typer as years go on, until you are mashing your head on the keyboard to type anything.


I dunno, I don't think that would really happen. I'm always trying to type the same word (I don't say "pish" in my head, after all, I think "push"), so it doesn't seem to be a random walk away from correctness, just some wavering around it. And it's not like I have that many commands I need to type commonly enough to make an alias for-- maybe a couple dozen? And for most of them, I don't make typos so I don't feel the need to make an alias.


alias gp="git push" has probably saved me hours of my life


Amen.

My bashrc has so many of these, and they're probably among the most common commands I use daily!:

    alias gs="git status"
    alias gb="git branch"
    alias grh="git reset --hard"
    alias gcdf="git clean -df"
    alias gf="git fetch"
    alias gp="git pull"
    alias gdom="git diff origin/master"
    alias gdomn="git diff --name-status origin/master"
    alias gd="git diff"
    alias gl="git log"
    alias glm="git log --author <my_name>"
    alias gc="git checkout"
    alias gcm="git checkout master"


I agree, but I am just too lazy for that. Mine are all one char:

  alias b='/usr/local/bin/git checkout -b'
  alias a='/usr/local/bin/git add
  alias d='/usr/local/bin/git diff HEAD'
  alias c='git commit -m'
  alias i='/usr/local/bin/git pull origin'
  alias o='/usr/local/bin/git branch -avv | grep "\*" | cut -d\ -f 2 | xargs -n 1 /usr/local/bin/git push -u origin'
plus:

  alias g='/usr/local/bin/git log --graph --oneline --decorate 
  alias v='/usr/local/bin/git branch -avv'--all'
  alias h='/usr/local/bin/git log -p'
can be useful.


Am I a bad person for creating SVN-style aliases for git?

From my .gitconfig:

    [alias]
            st = status
            ci = "!git add -u && git commit"
            di = diff
I come from an SVN background, I've since switched to Mercurial for my personal projects, and intensely dislike git, but have to use git at work, so I finally said "enough is enough" and made aliases so I can use git like svn/hg.


I use gcm for `git commit -m `, interestingly.

I only use a few git aliases, most things I'd rather type out.


I use Git Goodies, great list of aliases - https://github.com/qw3rtman/gg


Aliasing gs may be a bad idea, there is actually a command named like that (it's part of GhostScript)


Of course to each his own, but honestly, nothing I work on involves Ghostscript (or Postscript tbh) so not too much of a concern to me.

It's just so much quicker to recall stuff: [g]it [s]tatus :)


I have a similar set, plus

alias goto='git checkout'


Or how about git commit with a dummy message? :)


Oh dear. That reminds me of a story I saw here on HN at some point (might have been in the comments) about a dev team that didn't insist on any commit messages in their VCS, so everyone just put in a '.' to meet the requirement that a commit had to have a message for whatever source control system they were using.

My team doesn't have a strict commit message style guide, but good god it better be at least mildly descriptive of what's in the commit.

(I know you're joking, the thought of a 3 character alias to commit with a dummy message just sent shivers down my spine :)


Like this?

  $ cat << EOF > ~/.commit_reasons; strfile ~/.commit_reasons
  Testing...
  %
  Testify...
  %
  Testarossa...
  %
  Does it work yet?
  %
  How bout now?
  %
  Oops.
  %
  Fixed a thing.
  %
  EOF
  
  $ fortune ~/.commit_reasons | cowsay | git -F -



looks like oh-my-zsh ships with this... couldn't figure out why I had it already.


Git even has a wonderful autocorrect feature that you can enable with "git config --global help.autocorrect 1" This fixes commands like git pish or git ermote


For me it tends to be

$ git poop


as opposed to `git log`?


In case that wasn't a joke - no, `git pop`.


i constantly do:

git pull upsteam dev


For me it usually is "git remove" instead of "git remote".


Now do ffmpeg! (Seriously I would pay for autocomplete ffmpeg cmd line options)


It can't help with autocomplete, but I guses it would be easy to create a rule for fixing incorrect ffmpeg calls.

Create an issue about that in https://github.com/nvbn/thefuck/issues


This seems fairly similar to the command auto-correction in Oh My Zsh.


It's zsh itself, not Oh My Zsh, controlled via the `correct` option.


Thanks, I wasn't too sure. I have always used them together!


I use this app SO MUCH and recommend it to everyone. Great work!


What if I misspell the word "fuck"?


cursing is now provably productive


It's a nice utility. But I stopped using it because it keeps messing up my bash history.


+1 for not being PC


Actually, it does appear to work on PCs.


I think you are joking, but he meant PC as in Politically Correct


Geez that term is becoming more nebulous by the day


Imagine that one annoying pink busy body from Harry Potter. That's PC.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: