nvbn / thefuck

Magnificent app which corrects your previous console command.
MIT License
85.3k stars 3.43k forks source link

No longer works with an alias to “git push” #549

Closed progval closed 6 years ago

progval commented 8 years ago

Hi,

I recently installed a new system, but kept my old oh-my-zsh aliases. Before, I could type gp (alias for git push), and use thefuck to do the gp --set-upstream origin branchname for me. However, now the suggestion is gyp:

 dev-ipfs@particle  ~/rust-multiaddr   fix-protocol-codes  gp
fatal: The current branch fix-protocol-codes has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin fix-protocol-codes

 ✘ dev-ipfs@particle  ~/rust-multiaddr   fix-protocol-codes  f
gyp [enter/↑/↓/ctrl+c]
SimenB commented 8 years ago

@ProgVal for that case in particular you can do gpsup.

I've also noticed that aliased commands aren't fucked properly, though, would like a fix for that.

darrynten commented 7 years ago

👍

ahrenstein commented 7 years ago

+1. I opened a similar issue at #645

nvbn commented 7 years ago

Probably fixed in 3.17.

shssoichiro commented 7 years ago

This does not seem to be fixed in 3.17

Shir0kamii commented 7 years ago

I confirm this is not fixed, I'm in 3.18 and this is still present.

edwardsmit commented 7 years ago

I'm on 3.21 and this is not fixed. Using zsh 5.4.1 and a simple alias alias gp='git push'

scorphus commented 7 years ago

What do you get from the following command?

TF_ALIAS=fuck TF_SHELL_ALIASES=$(alias) PYTHONIOENCODING=utf-8 thefuck gp
edwardsmit commented 7 years ago

@scorphus No fucks given

The alias gp is set to git push

scorphus commented 7 years ago

Oh, sorry, I forgot to mention: make sure to run it from a Git repository with commits to be pushed. INW, run it in a scenario where it would correct a previous gp.

edwardsmit commented 7 years ago

@scorphus 🎉 You're on to something, because now it correctly generates the command I expect: git push --set-upstream origin feature/test [enter/↑/↓/ctrl+c]

scorphus commented 7 years ago

Great! So, what happens if, instead of that command I posted earlier, you run fuck? It should generate the same. Does it?

If it does: YAY! 🎉

If it doesn't: there might be something wrong with the way your fuck alias/function gets declared/interpreted/generated/whatever.

Waiting on you ;-)

edwardsmit commented 7 years ago

Unfortunately it doesn't. I verified that TheFuck is initialised after the alias is defined like so:

echo $(alias)
# TheFuck
eval "$(thefuck --alias)"

Which showed me that the aliases are defined before the first call to thefuck

gligoran commented 7 years ago

I'm having a similar issue:

$ ~/repo git:(my-branch) gp
fatal: The current branch my-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin my-branch

$ ~/repo git:(my-branch) fuck
No fucks given
$ ~/repo git:(my-branch) git push
fatal: The current branch my-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin my-branch

$ ~/repo git:(my-branch) fuck
git push --set-upstream origin my-branch [enter/↑/↓/ctrl+c]

I'm using Oh My Zsh with the git plugin. As you can see if I type out the git command, it works as it should, but it doesn't give a fuck for my alias.

I'm running this on a Ubuntu 14.04 that's running through vagrant.

edwardsmit commented 7 years ago

@scorphus Is there anything I can do to help you debug/fix this problem?

scorphus commented 7 years ago

@edwardsmit: the problem seems to be not with TehFuck itself but rather with the fuck function on your environment. You see, it works when you run thefuck manually. Let's try and identify where the problem might be. It may be a daunting process, so please bear with me. What are the outputs of the following two commands:

edwardsmit commented 7 years ago

@scorphus

type fuck
fuck is a shell function from /Users/edwardsmit/.zshrc
fuck is /usr/local/bin/fuck

functions fuck
fuck () {
        TF_PREVIOUS=$(fc -ln -1 | tail -n 1)
        TF_CMD=$(
                    TF_ALIAS=fuck
                    TF_SHELL_ALIASES=$(alias)
                    PYTHONIOENCODING=utf-8
                    thefuck $TF_PREVIOUS THEFUCK_ARGUMENT_PLACEHOLDER $*
                )  && eval $TF_CMD
        test -n "$TF_CMD" && print -s $TF_CMD
}
edwardsmit commented 7 years ago

@scorphus Is there anything I can help you with at this point?

edwardsmit commented 7 years ago

ping @scorphus

edwardsmit commented 6 years ago

Just tried out today, and seems fixed with 3.25 AFAIC this issue can be closed

scorphus commented 6 years ago

Hey @edwardsmit,

Glad it's working for you again! Thanks for keeping us posted.

Somehow I missed your replies, I'm really sorry about that. I'll review my notification settings.

So, I will close this one for now but if any of you users still experience this issue, please just reopen it.

hugovk commented 6 years ago

It's not working for me (on macOS High Sierra).

Info:

⌂66% [hugo:~/github/test] delete-me 3s 1 ± alias fuck
fuck='eval $(thefuck $(fc -ln -1)); history -r'
⌂69% [hugo:~/github/test] delete-me 2s ± brew info thefuck
thefuck: stable 3.25 (bottled), HEAD
Programatically correct mistyped console commands
https://github.com/nvbn/thefuck
/usr/local/Cellar/thefuck/3.25 (710 files, 6.3MB)
  Poured from bottle on 2017-12-04 at 15:32:19
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/thefuck.rb
==> Requirements
Required: python3 ✔
==> Caveats
Add the following to your .bash_profile, .bashrc or .zshrc:

  eval $(thefuck --alias)

For other shells, check https://github.com/nvbn/thefuck/wiki/Shell-aliases

Using gp doesn't work:

⌂66% [hugo:~/github/test] master 1 ± gco -b delete-me
Switched to a new branch 'delete-me'
⌂61% [hugo:~/github/test] delete-me ± alias gp
gp='git push'
⌂65% [hugo:~/github/test] delete-me ± gp
fatal: The current branch delete-me has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin delete-me
⌂65% [hugo:~/github/test] delete-me 128 ± fuck
gcp [enter/↑/↓/ctrl+c]
usage: git cherry-pick [<options>] <commit-ish>...
   or: git cherry-pick <subcommand>

    --quit                end revert or cherry-pick sequence
    --continue            resume revert or cherry-pick sequence
    --abort               cancel revert or cherry-pick sequence
    -n, --no-commit       don't automatically commit
    -e, --edit            edit the commit message
    -s, --signoff         add Signed-off-by:
    -m, --mainline <parent-number>
                          select mainline parent
    --rerere-autoupdate   update the index with reused conflict resolution if possible
    --strategy <strategy>
                          merge strategy
    -X, --strategy-option <option>
                          option for merge strategy
    -S, --gpg-sign[=<key-id>]
                          GPG sign commit
    -x                    append commit name
    --ff                  allow fast-forward
    --allow-empty         preserve initially empty commits
    --allow-empty-message
                          allow commits with empty messages
    --keep-redundant-commits
                          keep redundant, empty commits

fc: event not found: -r

Using git push works:

⌂119% [hugo:~/github/test] delete-me ± git push
fatal: The current branch delete-me has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin delete-me
⌂91% [hugo:~/github/test] delete-me 128 ± fuck
git push --set-upstream origin delete-me [enter/↑/↓/ctrl+c]
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/hugovk/test
 * [new branch]      delete-me -> delete-me
Branch 'delete-me' set up to track remote branch 'delete-me' from 'origin'.
fc: event not found: -r
scorphus commented 6 years ago

@hugovk your fuck alias definition looks odd – maybe it's very old. It should be a function instead. Take a look below.

For Bash:

fuck ()
{
    TF_PYTHONIOENCODING=$PYTHONIOENCODING;
    export TF_SHELL=bash;
    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;
    history -s $TF_CMD;
}

For ZSH:

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
}

For Fish:

function asdfasdf --description 'Correct your previous console command'
    set -l fucked_up_command $history[1]
    env TF_SHELL=fish TF_ALIAS=asdfasdf PYTHONIOENCODING=utf-8 thefuck $fucked_up_command | read -l unfucked_command
    if [ "$unfucked_command" != "" ]
        eval $unfucked_command
        builtin history delete --exact --case-sensitive -- $fucked_up_command
        builtin history merge ^/dev/null
    end
end

Please review your setup, specially in regards to the following:

==> Caveats
Add the following to your .bash_profile, .bashrc or .zshrc:

  eval $(thefuck --alias)

For other shells, check https://github.com/nvbn/thefuck/wiki/Shell-aliases
hugovk commented 6 years ago

@scorphus Thanks, that fixed it!

You were right, I had an old alias fuck='eval $(thefuck $(fc -ln -1)); history -r' in my .zshrc, replacing that with eval $(thefuck --alias) gives this:

94% [hugo:~] 1 % which fuck
fuck () {
    TF_PREVIOUS=$(fc -ln -1 | tail -n 1)
    TF_CMD=$( TF_ALIAS=fuck TF_SHELL_ALIASES=$(alias) PYTHONIOENCODING=utf-8 thefuck $TF_PREVIOUS THEFUCK_ARGUMENT_PLACEHOLDER $* )  && eval $TF_CMD
    test -n "$TF_CMD" && print -s $TF_CMD
}
⌂71% [hugo:~/github/test] delete-me3 ± gp
fatal: The current branch delete-me3 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin delete-me3
⌂71% [hugo:~/github/test] delete-me3 128 ± fuck
git push --set-upstream origin delete-me3 [enter/↑/↓/ctrl+c]
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/hugovk/test
 * [new branch]      delete-me3 -> delete-me3
Branch 'delete-me3' set up to track remote branch 'delete-me3' from 'origin'.
Jean85 commented 6 years ago

I'm currently having this issue using the OhMyZsh plugin. I have just installed my machine, so it's all perfectly clean.

The plugin seems to be in order: https://github.com/robbyrussell/oh-my-zsh/blob/ebda8af870acc295388ed187f0139a8bffa83196/plugins/thefuck/thefuck.plugin.zsh#L7

How can I debug this further? I'm using The Fuck 3.27 using Python 3.6.5