nvbn / thefuck Goto Github PK
View Code? Open in Web Editor NEWMagnificent app which corrects your previous console command.
License: MIT License
Magnificent app which corrects your previous console command.
License: MIT License
I really love this pretty app..
but in my zsh , when I input a command like puthon
, it told me
puthon
zsh: command not found: puthon
so thefuck seems did not work... Could you tell me how can I configure zsh ?
Thanks
$ apt-get update
E: Не удалось открыть файл блокировки /var/lib/apt/lists/lock - open (13: Отказано в доступе)
E: Невозможно заблокировать каталог /var/lib/apt/lists/
E: Не удалось открыть файл блокировки /var/lib/dpkg/lock - open (13: Отказано в доступе)
E: Не удалось выполнить блокировку управляющего каталога (/var/lib/dpkg/); у вас есть права суперпользователя?
$ fuck
Traceback (most recent call last):
File "/usr/local/bin/thefuck", line 9, in <module>
load_entry_point('thefuck==1.7', 'console_scripts', 'thefuck')()
File "/usr/local/lib/python2.7/dist-packages/thefuck/main.py", line 91, in main
matched_rule = get_matched_rule(command, rules, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/main.py", line 67, in get_matched_rule
if rule.match(command, settings):
File "/usr/local/lib/python2.7/dist-packages/thefuck/utils.py", line 41, in wrapper
return fn(command, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/rules/no_command.py", line 19, in match
output = _get_output(command, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/rules/no_command.py", line 13, in _get_output
return result.stderr.read().decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
I'd like to fix a command with a loud swear word :D
I'm using fish shell.
This works:
> pacman -S python
error: you cannot perform this operation unless you are root.
> fuck
sudo pacman -S python
[sudo] password for v:
This fails:
> pacman -S (echo python)
error: you cannot perform this operation unless you are root.
> fuck
No fuck given
I suspect it's trying to execute it with bash to get the output
Line 60 in 235b31e
Is there a way to make sure it executes with the correct shell?
Is there a way to install this on Windows?
Rules in which get_new_command returns a zsh alias result in command not found errors. Example:
> alias
[...]
baz='echo "it worked!"'
[...]
> cat .thefuck/rules/aliastest.py
def match(command, settings):
return (command.script == 'foo')
def get_new_command(command, settings):
return 'baz'
> foo
zsh: command not found: foo
> fuck
baz
zsh: command not found: baz
I was searching why it was no giving a fuck when I was trying to use it.
Then I saw this PR:
https://github.com/nvbn/thefuck/pull/30/files
It seems that thefuck is checking for hard coded errors messages so obviously it can't work with other languages than English and the current approach can't allow it.
Any idea how to detect permission errors in a language agnostic way?
For git it should be possible to use the last line of the ouput which contains only the corrected command and nothing language specific.
woverton@pc-wover-06:~$ cat /etc/lsb-release
DISTRIB_ID="elementary OS"
DISTRIB_RELEASE=0.3
DISTRIB_CODENAME=freya
DISTRIB_DESCRIPTION="elementary OS Freya"
woverton@pc-wover-06:~$ apt-get update
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
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?
woverton@pc-wover-06:~$ fuck
Traceback (most recent call last):
File "/usr/local/bin/thefuck", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 444, in _build_master
ws.require(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 725, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: psutil
woverton@pc-wover-06:~$
Dafuq is funny and meme worthy. Canonical example of "dafuq" usage is this vine video:
I think the title says it all.
I wish to add my own fuck. Any help as to where do I do that and how? Particularly I wish to add fuck for cd
command whenever directory is not found i automatically creates one using mkdir. I also want to do so when given a parameter to fuck say fuck hard
Default install on OS X with pip doesn't seem to do anything other than return "No fucks given," even with example rules imported. This might not be a code issue--there might be additional setup missing from the documentation.
On most recent version (1.1.8) I get this error on OSX 10.10.13 when calling fuck
. I assume it has something to do with the $PATH walk on the most recent commit. If this is a permissions error, which it almost certainly is, can it be solved programmatically such that future users don't have to chmod 777
anything to get this CLI to work? Can look in more detail tomorrow, but for now this is all I have.
Traceback (most recent call last):
File "/usr/local/bin/thefuck", line 9, in <module>
load_entry_point('thefuck==1.18', 'console_scripts', 'thefuck')()
File "/usr/local/lib/python2.7/site-packages/thefuck/main.py", line 136, in main
matched_rule = get_matched_rule(command, rules, settings)
File "/usr/local/lib/python2.7/site-packages/thefuck/main.py", line 93, in get_matched_rule
if rule.match(command, settings):
File "/usr/local/lib/python2.7/site-packages/thefuck/rules/no_command.py", line 16, in match
_get_all_bins()))
File "/usr/local/lib/python2.7/site-packages/thefuck/rules/no_command.py", line 10, in _get_all_bins
if exe.is_file()]
File "/usr/local/lib/python2.7/site-packages/pathlib.py", line 1202, in is_file
return S_ISREG(self.stat().st_mode)
File "/usr/local/lib/python2.7/site-packages/pathlib.py", line 1051, in stat
return self._accessor.stat(self)
File "/usr/local/lib/python2.7/site-packages/pathlib.py", line 346, in wrapped
return strfunc(str(pathobj), *args)
OSError: [Errno 13] Permission denied: '/usr/sbin/weakpass_edit'
Which should, of course, be WTFPL.
It would be a nice feature to correct the command and the history.
I would also like an option to not add {fuck,thefuck} to the history.
I installed this and relaunched. Then I act like title.
$ fuck
The terminal got stuck.
I quitted the terminal, and relaunched twice.
$ fuck
No fuck given
It worked well.
I am using OS X 10.10.3 + iterm(zsh) + python 2.7.6
$history[1] holds the latest command, in this case fuck
.
Для примера:
"св юю" --> "cd .."
"ды -дф" --> "ls -la"
Я сделал несколько правил для самых моих популярных опечаток в раскладке.
Но хочется общее красивое))
How about this feature?
Thoughts on adding these features?
fuck this <rule name> [hard] [<match rules>] <command spec>
fuck that <rule name> [hard] [<match rule>]
I believe WTFPL licence might be quite appropriate for this project:
http://www.wtfpl.net/about/
I create a simple rule for my own usage here : https://gist.github.com/fzerorubigd/c8b53fa3231f28f40092
Some time, I type command in another keyboard layout, (as you can see, persian) and I want to use fuck to fix that (I already build a command not found handler, but fuck is better :) )
the problem is, if I use an alias, then the result is detected, but it can not execute it :
$ alias tst=ls
$ فسف
zsh: command not found: فسف
$ fuck
tst
zsh: command not found: tst
I use zsh 5.0.7 and python 3.4.3 (Archlinux) with thefuck from comunity (and also tested against the master branch and the pip version)
I'll just leave it here
Traceback (most recent call last):
File "/usr/local/bin/thefuck", line 9, in
load_entry_point('thefuck==1.9', 'console_scripts', 'thefuck')()
File "/usr/local/lib/python2.7/dist-packages/thefuck/main.py", line 93, in main
matched_rule = get_matched_rule(command, rules, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/main.py", line 69, in get_matched_rule
if rule.match(command, settings):
File "/usr/local/lib/python2.7/dist-packages/thefuck/utils.py", line 41, in wrapper
return fn(command, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/rules/no_command.py", line 19, in match
output = _get_output(command, settings)
File "/usr/local/lib/python2.7/dist-packages/thefuck/rules/no_command.py", line 13, in _get_output
return result.stderr.read().decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 24: ordinal not in range(128)
This doesn't work for me:
function fuck
thefuck $history[2] | source
end
This works for me:
function fuck
thefuck $history[1] | source
end
It would be great to support maven commands. See example below. (should be mvn clean install
, see last lines of the stack trace)
$ mvn clean insta
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Camel :: Example :: Twitter WebSocket 2.15.1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.536 s
[INFO] Finished at: 2015-04-18T23:15:13+03:00
[INFO] Final Memory: 22M/981M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "insta". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
$ fuck
No fuck given
I'm a Linux user and working with shell commands every day. My system's default language is Chinese, so the output messages of some commonly used tools (git, gcc, etc.) were translated into Chinese in the i18n mechanism of the software itself. So I think it is considerable to match i18n messages.
Do you have any ideas to implement this feature? It may be gossip to write strings of all languages in the match function. Can there be any more beautiful ways to make it?
$ puthon
-bash: puthon: command not found
$ fuck
No fuck given
The install instructions for Fish says to define
function fuck
eval (thefuck (history | head -n1))
end
This won't work, because history
will include the currently-executing command in its output, which means that this will always evaluate to eval (thefuck fuck)
. It's also rather wasteful, as history
dumps a bunch of history. There's also the curious property wherein if thefuck
emits multiple lines, they'll end up being joined into a single line, as command substitution splits lines into arguments, and eval
joins multiple arguments with spaces instead of newlines.
Both of these issues can be fixed by rewriting it as
function fuck
thefuck $history[2] | source
end
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.
Installation
...
If it fails try to use easy_install:
sudo easy_intall thefuck
should be:
sudo easy_install thefuck
also, running "fuck" did not solve this typo in the README.md ;)
PS: Thanks for adding joy to the command line!
In your doc you mention that one needs to create an alias in order to make thefuck work.
Is there a reason why you did not implement it the way that thefuck directly launches the new command without echoing it back to the subshell? This way it would be easier to setup.
Hello,
I want to create a new rule based on the cd
command, but I noticed that the returned error is not the same when I use bash or sh.
With bash :
$ cd foo
bash: cd: foo: No such file or directory
With sh :
$ cd foo
sh: 1: cd: can't cd to foo
And when I print command.stderr
in the match()
function, the stderr is the sh style. So my question is : when we create a new rule, should we use this stderr style to test errors?
Thank you 😃
I'm trying to create a fuck for cd: no such file or directory: <directory_name>
which gets converted to mkdir <directory_name>.
I wrote following for match function but is says No fuck given
def match(command, settings):
return ("cd: no such file or directory:" in command.stderr)
I tried printing stderr which contains /bin/sh: 1: cd: can't cd to <directory_name>
. Why is it so and where do I get "cd: no such file or directory:"
[jurikolo@t2001542 ~]$ rpm -q python
python-2.7.8-8.fc21.x86_64
[jurikolo@t2001542 ~]$ rpm -q python3
python3-3.4.1-16.fc21.x86_64
[jurikolo@t2001542 ~]$ rpm -q python-pip
python-pip-1.5.6-3.fc21.noarch
[jurikolo@t2001542 ~]$ sudo pip install thefuck
Downloading/unpacking thefuck
Downloading thefuck-1.23.tar.gz
Running setup.py (path:/tmp/pip-build-DiyXNk/thefuck/setup.py) egg_info for package thefuck
Downloading/unpacking pathlib (from thefuck)
Downloading pathlib-1.0.1.tar.gz (49kB): 49kB downloaded
Running setup.py (path:/tmp/pip-build-DiyXNk/pathlib/setup.py) egg_info for package pathlib
Downloading/unpacking psutil (from thefuck)
Downloading psutil-2.2.1.tar.gz (223kB): 223kB downloaded
Running setup.py (path:/tmp/pip-build-DiyXNk/psutil/setup.py) egg_info for package psutil
warning: no previously-included files matching '*' found under directory 'docs/_build'
Installing collected packages: thefuck, pathlib, psutil
Running setup.py install for thefuck
Installing thefuck script to /usr/bin
Running setup.py install for pathlib
Running setup.py install for psutil
building '_psutil_linux' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_VERSION=221 -I/usr/include/python2.7 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.7/psutil/_psutil_linux.o
psutil/_psutil_linux.c:12:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-DiyXNk/psutil/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-EWe0Tg-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/psutil
copying psutil/_pswindows.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_pslinux.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_psposix.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_psbsd.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_pssunos.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_psosx.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_common.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/_compat.py -> build/lib.linux-x86_64-2.7/psutil
copying psutil/init.py -> build/lib.linux-x86_64-2.7/psutil
running build_ext
building '_psutil_linux' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/psutil
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_VERSION=221 -I/usr/include/python2.7 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.7/psutil/_psutil_linux.o
psutil/_psutil_linux.c:12:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;file='/tmp/pip-build-DiyXNk/psutil/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-EWe0Tg-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-DiyXNk/psutil
Storing debug log for failure in /root/.pip/pip.log
[jurikolo@t2001542 ~]$
[jurikolo@t2001542 ~]$
[jurikolo@t2001542 ~]$
[jurikolo@t2001542 ~]$ sudo easy_install thefuck
Searching for thefuck
Best match: thefuck 1.23
Adding thefuck 1.23 to easy-install.pth file
Installing thefuck script to /usr/bin
Using /usr/lib/python2.7/site-packages
Processing dependencies for thefuck
Searching for psutil
Reading https://pypi.python.org/simple/psutil/
Best match: psutil 2.2.1
Downloading https://pypi.python.org/packages/source/p/psutil/psutil-2.2.1.tar.gz#md5=1a2b58cd9e3a53528bb6148f0c4d5244
Processing psutil-2.2.1.tar.gz
Writing /tmp/easy_install-bOMCvU/psutil-2.2.1/setup.cfg
Running psutil-2.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-bOMCvU/psutil-2.2.1/egg-dist-tmp-zl8pT0
warning: no previously-included files matching '*' found under directory 'docs/_build'
psutil/_psutil_linux.c:12:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
thefuck/thefuck/rules/no_command.py
blindly looks for /usr/lib/command-not-found
which does not exist on Windows, OS X, or a great many Linux distributions (Debian, for example).
I'd like to suggest a more cross-platform method of finding the correct command:
$PATH
[or running hash
if you have a $SHELL
instance])
alias
in $SHELL
and get the list of aliases, too.original_command
amongst the listThis should make this glorious project even more useful to all the sysadmins on SpecialSnowflakeCustomLinuxDistro and maybe even those stuck on Windows.
Jonathans-MacBook-Pro:studio jong$ git checkout amster
error: pathspec 'amster' did not match any file(s) known to git.
Jonathans-MacBook-Pro:studio jong$ fuck
No fuck given
alias please='sudo $(history -p !!)'
Just sharing a handy bash alias.
So that I know what will be ran
fuck --dry-run
AI apocalypse imminent. Fuck.
I created an AUR package for Arch Linux. This makes it easy for users to install on Arch. Not sure if you want to add a note to the install section or not.
I'm not super familiar with implementing tab completion but think it would be handy to be able to preview the suggested command before running it. For example here is the workflow I would like:
$ git push<enter>
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
$ fuck<tab> # tab completion replaces the entire line
$ git push --set-upstream origin master<enter>
git push --set-upstream origin master
Counting objects: 9, done.
For example:
1.
➜ brew docto
Error: Unknown command: docto
➜ brew install elsticsearch
Error: No available formula for elsticsearch
Searching formulae...
Searching taps...
For example, git brnch
gives 1
for echo $?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.