Thefuck: Cannot run fuck in zsh without export errors

Created on 26 Oct 2017  ·  15Comments  ·  Source: nvbn/thefuck

Installed via pip. Ran eval "$(thefuck --alias)" in both bash and zsh. $ fuck then produces 'No fucks given' in bash while in zsh it complains about invalid arguments.

$ eval "$(thefuck --alias)"
$ fuck
fuck:export:3: not valid in this context: -'
fuck:3: not an identifier: [skip

Also FWIW:

$ zsh --version
zsh 4.3.11 (x86_64-redhat-linux-gnu)
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.8 (Santiago)
next release

Most helpful comment

it seems that was a issue of zsh.

when run export TF_SHELL_ALIASES=$(alias) in zsh, you can see the same error.

run unalias -- - and this error will disappear, but another error comes.

my way to deal with this problem is not use eval "$(thefuck --alias)" in ~/.zshrc

run thefuck --alias in your shell, delete the line which contain export TF_SHELL_ALIASES=$(alias), and write the output in your .zshrc

just like

fuck () {
    TF_PYTHONIOENCODING=$PYTHONIOENCODING;
    export TF_ALIAS=fuck;
    export TF_HISTORY="$(fc -ln -10)";
    export PYTHONIOENCODING=utf-8;
    TF_CMD=$(
        thefuck THEFUCK_ARGUMENT_PLACEHOLDER $@
    ) && eval $TF_CMD;
    unset TF_HISTORY;
    export PYTHONIOENCODING=$TF_PYTHONIOENCODING;
    test -n "$TF_CMD" && print -s $TF_CMD
}

It may not the best way to deal with this problem, but it really works.

All 15 comments

Almost same problem here:

$ fuck
fuck:export: not valid in this context: -'
pyenv:11: command not found: pyenv                                                                                                                                                                                                                                                                                                                                        
prompt_context:10: command not found: whoami
prompt_dir:1: command not found: sed
prompt_background_jobs:1: command not found: wc
prompt_background_jobs:2: command not found: awk

Additional info:

$ zsh --version                                                                                                                                                                                                                                                                                                     
zsh 5.4.2 (x86_64-apple-darwin15.6.0)
$ sw_vers                                                                                                                                                                                                                                                                                                           
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G17023

it seems that was a issue of zsh.

when run export TF_SHELL_ALIASES=$(alias) in zsh, you can see the same error.

run unalias -- - and this error will disappear, but another error comes.

my way to deal with this problem is not use eval "$(thefuck --alias)" in ~/.zshrc

run thefuck --alias in your shell, delete the line which contain export TF_SHELL_ALIASES=$(alias), and write the output in your .zshrc

just like

fuck () {
    TF_PYTHONIOENCODING=$PYTHONIOENCODING;
    export TF_ALIAS=fuck;
    export TF_HISTORY="$(fc -ln -10)";
    export PYTHONIOENCODING=utf-8;
    TF_CMD=$(
        thefuck THEFUCK_ARGUMENT_PLACEHOLDER $@
    ) && eval $TF_CMD;
    unset TF_HISTORY;
    export PYTHONIOENCODING=$TF_PYTHONIOENCODING;
    test -n "$TF_CMD" && print -s $TF_CMD
}

It may not the best way to deal with this problem, but it really works.

It appears that the export won't allow aliases that start with non alphanumeric characters. I made this change to the third line:

TF_SHELL_ALIASES = $(alias | grep "^[a-zA-Z0-9]")
And it seems to be working fine for me now.

I have the same issue. Is there an official fix?

Hello! I cannot reproduce this one:

$ eval "$(thefuck --alias fuck)"
$ fuck
Nothing found
$ functions fuck
fuck () {
    TF_PYTHONIOENCODING=$PYTHONIOENCODING 
    export TF_SHELL=zsh 
    export TF_ALIAS=fuck 
    export TF_SHELL_ALIASES=$(alias) 
    export TF_HISTORY="$(fc -ln -10)" 
    export PYTHONIOENCODING=utf-8 
    TF_CMD=$(
                    thefuck THEFUCK_ARGUMENT_PLACEHOLDER $@
                )  && eval $TF_CMD
    unset TF_HISTORY
    export PYTHONIOENCODING=$TF_PYTHONIOENCODING 
    test -n "$TF_CMD" && print -s $TF_CMD
}
$ alias @asdf='echo this is asdf'
$ alias _wow='echo wow alias'        
$ alias
@asdf='echo this is asdf'
_wow='echo wow alias'
which-command=whence
$ @asdf
this is asdf
$ @@asdf
zsh: command not found: @@asdf
$ fuck
@asdf [enter/↑/↓/ctrl+c]
this is asdf

Versions:

$ grep RELEASE= /etc/linuxmint/info
RELEASE=18.3
$ zsh --version
zsh 5.1.1 (x86_64-ubuntu-linux-gnu)
$ thefuck --version
The Fuck 3.25 using Python 3.6.1

Looks like I'm missing something. But what?

~p.s.1: I'll try with a newer zsh and post the results~
p.s.2: I tested with zsh 5.4.2 (x86_64-alpine-linux-musl) and the results are the same as above

@scorphus Thefuck works fine on Ubuntu with zsh, but I met the above problem on mac.

What zsh version, @SilvesterHsu?

@scorphus zsh 5.4.2 (x86_64-apple-darwin14.5.0) on mac, and zsh 5.1.1 (x86_64-ubuntu-linux-gnu) on Ubuntu.

having this exact issue on mac as well - zsh 5.2 (x86_64-apple-darwin15.6.0)

have this same issue on mac. any solution?

I still can't reproduce this issue. Can you please share your aliases? IWO output of alias omitting any sensitive information, of course. Thanks.

I have this problem with zsh 5.0.2 (x86_64-pc-linux-gnu) and have the alias output as following:

fuck () {
                TF_PYTHONIOENCODING=$PYTHONIOENCODING;
                export TF_SHELL=zsh;
                export TF_ALIAS=fuck;
                export TF_SHELL_ALIASES=$(alias);
                export TF_HISTORY="$(fc -ln -10)";
                export PYTHONIOENCODING=utf-8;
                TF_CMD=$(
                    thefuck THEFUCK_ARGUMENT_PLACEHOLDER $@
                ) && eval $TF_CMD;
                unset TF_HISTORY;
                export PYTHONIOENCODING=$TF_PYTHONIOENCODING;
                test -n "$TF_CMD" && print -s $TF_CMD
            }

I have the same problem in zsh. You can fix this by quoting the output from "alias":

traal% echo $ZSH_VERSION
4.3.10
traal% unalias -m '*'         # remove all aliases
traal% alias
traal% alias ll='ls -a'
traal% alias
ll='ls -a'
traal% foo=$(alias)           # this works!
traal% export foo=$(alias)    # this breaks...
export: not valid in this context: -a'
traal% export foo="$(alias)"  # works again
traal% print $foo
ll='ls -a'

I confirmed that this works as expected with thefuck too.

In other words; the proper fix is to change:

export TF_SHELL_ALIASES=$(alias);

To:

export TF_SHELL_ALIASES="$(alias)";

So this is not an issue anymore since some 5.2 minor (?) version:

1b23d830ba7f# echo $ZSH_VERSION
5.2
1b23d830ba7f# zsh --version
zsh 5.2 (x86_64-alpine-linux-musl)
1b23d830ba7f# unalias -m '*'
1b23d830ba7f# alias
1b23d830ba7f# alias ll='ls -a'
1b23d830ba7f# alias
ll='ls -a'
1b23d830ba7f# foo=$(alias)
1b23d830ba7f# export foo=$(alias)
1b23d830ba7f# export foo="$(alias)"
1b23d830ba7f# print $foo
ll='ls -a'

Zsh 5.2 was released almost 3 years ago.

The question now is: should we support old versions?

Please cast your vote with either 👍 or 👎 reaction to this very message:

image

Thanks!

it seems that was a issue of zsh.

when run export TF_SHELL_ALIASES=$(alias) in zsh, you can see the same error.

run unalias -- - and this error will disappear, but another error comes.

my way to deal with this problem is not use eval "$(thefuck --alias)" in ~/.zshrc

run thefuck --alias in your shell, delete the line which contain export TF_SHELL_ALIASES=$(alias), and write the output in your .zshrc

just like

fuck () {
    TF_PYTHONIOENCODING=$PYTHONIOENCODING;
    export TF_ALIAS=fuck;
    export TF_HISTORY="$(fc -ln -10)";
    export PYTHONIOENCODING=utf-8;
    TF_CMD=$(
        thefuck THEFUCK_ARGUMENT_PLACEHOLDER $@
    ) && eval $TF_CMD;
    unset TF_HISTORY;
    export PYTHONIOENCODING=$TF_PYTHONIOENCODING;
    test -n "$TF_CMD" && print -s $TF_CMD
}

It may not the best way to deal with this problem, but it really works.

fantastic

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whereistejas picture whereistejas  ·  4Comments

jabbson picture jabbson  ·  4Comments

shelbyKiraM picture shelbyKiraM  ·  5Comments

disjunto picture disjunto  ·  6Comments

radjivF picture radjivF  ·  4Comments