The Fuck – Correct your previous console command
github.com
github.com
!^ - 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 !!^foo^bar
git brnch
^r^ra
This works on all Unix machines
You can also just run a sed style substitution in most shells, e.g. '$ !!:s/before/after/' or '$ !!:gs/x/y/', which is safer IMO.
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.
:w !sudo tee %
If you neglected to sudo before making your changes. " Let :w!! gain sudo privileges without closing and reopening vim
cmap w!! w !sudo tee % >/dev/nullhttp://stackoverflow.com/questions/2600783/how-does-the-vim-...
Also, after you have entered a previous command, to edit it, or any previous command in the history, the first thing you have to do is press ESC (to go to command mode) and then k, thereby bring the last entered command into view for editing.
When editing a command, but in command mode (not insert/append mode), you can also press v to open the command in vi(m) in a temporary file, then have the full screen editor at your disposal to edit the command (useful for long scripts including for/while loops or long pipelines), and then when you save and exit (:wq or :x followed by Enter), the newly edited command gets executed by bash.
Also, this editing technique is useful not only for correcting typos in commands, but for modifying a previous correct command, to change some words in it and then re-issue it.
$ ls -l /tmp/foo
ls: cannot access /tmp/foo: No such file or directory
$ !:s/foo/bar
-rw-rw-r-- 1 user user 0 Apr 17 19:12 /tmp/bar $ ls -l /tmp/foo
ls: cannot access /tmp/foo: No such file or directory
$ ^foo^bar
-rw-rw-r-- 1 user user 0 Apr 17 19:12 /tmp/bar $ ls
hello_world hi_there_world
$ mv hello_world hello_everyone
$ !!:gs/hello/hi_there
mv hi_there_world hi_there_everyone
$ ls
hi_there_world hi_there_everyoneatom path/to/so[tab]/fi[tab] [return] git diff $_
Complete reference: https://www.gnu.org/software/bash/manual/html_node/Variable-...
Preventing typo mistakes with bash autocomplete is even better than correcting mistakes afterwards, it also makes typing so much faster. It works with commands AND it also works for files inside the current working directory.
Hint: start typing your command and then hit TAB, voilà! Note: if there are more than 1 command/file option that starts with the same chars you wrote, hit TAB twice and you will have all the options displayed in front of you, it comes in handy to remember fast instead of browsing documentation.
Command example:
$ git rem[TAB] ---> $ git remote
$ git remote a[TAB] ---> $ git remote add
File example:
$ git add i[TAB] --> $ git add index.js
Multiple options example (TAB twice):
$ git r[TAB,TAB]
(will give you the options:)
rebase relink replace revert reflog remote request-pull rm release repack reset
The result is NO TYPOS! ;)
--------------------------
It would also be worth remembering the unix convention of using $ for regular user prompt and # for super user prompt.
In other words:
$ <--- if this is your prompt you're working on a regular user session.
# <--- if this is your prompt you're working on a super user session and you don't need sudo.
Again, that is just a convention, your OS/distro could be different.
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. # 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. 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-configAnd yet the concept of the invocation `fuck --dry-run` is surely unappealing. :-)
fuck --without-condom
or maybe fuck --iamfeelinglucky$ apt-get install foo<return> $ fuck<return> -> sudo apt-get install foo<return>
zsh does something similar for history commands, I think:
$ echo foo foo $ echo !$<return> -> $ echo foo
fuck<return><return>
which is probably good enough. (Pressing the same key twice is pretty much the same as pressing one key, but pressing two different keys is harder.)Far more easier to press CTRL-T than type `fuck` every time.
http://zsh.sourceforge.net/Guide/zshguide06.html#l162
http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.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.
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
That was my impression. It reminded me of little custom scripts or functions I've created that help with my day to day work, things I wouldn't necessarily give to someone because they were built with myself in mind. I know how they work and exactly what they do.
I like it, but I have to know every command it modifies/checks, I cannot run a blackbox command and hope.
I just added an additional alias for testing.
It simply outputs the command fuck would execute:
alias tryfuck='thefuck $(fc -ln -1)'And yep, it can add sudo to your previous rm -rf /.
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.
Very useful though.
There really needs to be better communication between software and the environment it's running in.
All it does is print the command to run and prompts for [Y/n].
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.
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.
It is a nice idea, though. Will use it if it's called auto-correct or something.
... because people want to treat them differently, perhaps?
But there are plenty of out-groups in technology along plenty of lines, who may privately be uncomfortable in this situation; and gender is only one of those lines.
If we pretend there is no problem with gender that needs addressing in this respect, it's not that we are excluding women: it's that we are excluding every aspect of diversity in technology.
alias doh='$(thefuck $(fc -ln -1))'alias WTFs="history | grep fuck | wc -l"
function fuck
eval (thefuck (history | head -n1))
endI thought the cardinal rule of sysadmins was "think before you press enter". This seems to discourage that mindset.
Also was asked to install "suck." Not sure why / what that is.
To err is human, to really fuck things up requires a computer.
$ wrongcommand
error
$ fcuk
command not found
$ fuck <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. export EDITOR=vim
C-p (or Up)
C-x C-e$ fc
permission denied
$ fuck
sudo rm -rf --no-preserve-root / oops
$ _
Most actual instances of the actual word "fuck" aren't even swears.
Sounds like you need a review of: 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.
Also:
http://www.whatthefuckshouldimakefordinner.com/
etc.
It's not a trivial question, though, and people aren't wrong to disagree. Cultural differences make for very different views here. In some (sub-)cultures swear words are uncivil and in others they are innocuous. There's no model that satisfies all these norms, so inevitably we have to disappoint some.
As a consequence of the above, we don't bowdlerize titles either.
Late night, vision is starting to blur and you've typed `git push origin master` incorrectly dozens of times already...
$ FUCK!!!111ksjdkjsd alias fuck='$(thefuck $(fc -ln -1))'Looks like someone already has, actually: https://github.com/shaungallagher/thefudge
But seriously, I can't some up with a single situation where using "fudge/crap" instead of fuck would matter.
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.
Which social contexts? Social contexts where people don't know what "WTF" expands to? It's not even a "minced oath".
"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.
~> wtf is imnsho
IMNSHO: in my not so humble opinion
~> wtf is cat
SVK::Command::Cat(3pm) - Output the file from depot
cat(1) - concatenate and print files
fc-cat(1) - read font information cache files
git-cat-file(1) - Provide content or type and size information for repository objects
~> wtf is fuck
fuck: nothing appropriate
http://cvsweb.netbsd.org/bsdweb.cgi/src/games/wtf/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.
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...
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.