Code Monkey home page Code Monkey logo

thefuck's Issues

does not work well with zsh...

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

Some Unicode error in Ubuntu 14.10

$ 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)

doesn't seem to work with more complex commands with non-standard shells

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

result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,

Is there a way to make sure it executes with the correct shell?

TheFuck doesn't see my zsh aliases :(

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

Support other languages/locales than English

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.

Does not work in Elementary OS Freya

OS version:

woverton@pc-wover-06:~$ cat /etc/lsb-release
DISTRIB_ID="elementary OS"
DISTRIB_RELEASE=0.3
DISTRIB_CODENAME=freya
DISTRIB_DESCRIPTION="elementary OS Freya"

Using Fuck

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:~$

add a fuck

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

Output is always "No fucks given"

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.

Fuck permission denied

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'

terminal get stuck when no previous commands are given.

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

fuck this and fuck that

Thoughts on adding these features?

fuck this

  • fuck this <rule name> [hard] [<match rules>] <command spec>
  • Adds <rule name>.py to rules dir with match/command args
  • Somehow determines match rules if not provided
  • Prompts for confirmation after outputting generated file name & code
  • 'hard' argument skips confirmation

fuck that

  • fuck that <rule name> [hard] [<match rule>]
  • To be used after running correct command
  • argument functionality same as with "fuck this ..."
  • command is generated from previously executed command

Things to think about

  • How to specify a rule/command without typing Python on command line
    • Grammar for defining where to match (script/stdout/stderr), what to match, and logical combinations
    • Grammar for command or just take command string?
    • easier to just accept Python from command line?
  • Automatically call 'fuck' after 'fuck this'?
  • Ditch the args except for rule name & open default editor with generated boilerplate rule with script/stdout/stderr included in comments at top of file?

Running alias

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)

Issue with decoding/non-English terminal

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)

fish function in readme is wrong

This doesn't work for me:

function fuck
    thefuck $history[2] | source
end

This works for me:

function fuck
    thefuck $history[1] | source
end

add maven support

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

How about i18n?

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?

Install instructions for Fish are wrong

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

running "fuck" twice almost gave me a heartattack

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.

README.md easy_intall typo

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!

Running fuck just after nano freezes the shell

$ nano whateverfile, quitting Nano, and immediately running fuck freezes the entire shell (zsh with ohmyzsh) on OSX 10.10 (developer preview FWIW – I never bothered to install the stable version).

image

Remove need for the shell alias

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.

What command line interpreter used for rules

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 😃

cd to mkdir

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:"

Doesn't work on Fedora 21

[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` is not cross-platform

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:

  • enumerate the list of executables (almost certainly by walking $PATH [or running hash if you have a $SHELL instance])
    • This would be a great chance to also run alias in $SHELL and get the list of aliases, too.
  • find the lowest Levenshtein distance from original_command amongst the list
  • return it

This should make this glorious project even more useful to all the sysadmins on SpecialSnowflakeCustomLinuxDistro and maybe even those stuck on Windows.

feature request: common git branch typos

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

Is it possible for tab completion to replace "fuck" with the command it is going to execute?

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.

Add support mistakes in homebrew command

For example:
1.

➜ brew docto
Error: Unknown command: docto
➜ brew install elsticsearch
Error: No available formula for elsticsearch
Searching formulae...
Searching taps...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.