Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Fish shell aliases seems to be broken #727

Closed
andyleejordan opened this issue Nov 6, 2017 · 3 comments · Fixed by #753
Closed

Parsing Fish shell aliases seems to be broken #727

andyleejordan opened this issue Nov 6, 2017 · 3 comments · Fixed by #753

Comments

@andyleejordan
Copy link

In ~/.config/fish/conf.d/aliases.fish I have alias g 'git' (a common alias, I think, for g -> git). This alias works, and even Fish auto-completion recognizes it and works.

I'm running fish, version 2.6.0 with The Fuck 3.24 using Python 3.6.3, and just updated ~/.config/fish/functions/fuck.fish to be:

function fuck -d "Correct your previous console command"
  set -l fucked_up_command $history[1]
  env TF_ALIAS=fuck 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

The fuck alias works for me, except, it's not resolving aliases!

I added a new rule to ~/.config/thefuck/rules/git_worktree_checkout.py:

import re
from thefuck.specific.git import git_support

@git_support
def match(command):
    return ('checkout' in command.script
            and 'fatal:' in command.output
            and 'is already checked out at' in command.output)

@git_support
def get_new_command(command):
    directory_name = re.findall(
        r"fatal: '[^']+' is already checked out at '([^']+)'" , command.output)[0]
    return 'cd {}'.format(directory_name)

To fix the scenario of checking out a branch that's already checked out in another Git worktree. Using the @git_support, my Git aliases (i.e. co -> checkout) are expanded properly, but Fish gives me No fucks given if I try to use g instead of git.

$ pwd
/home/andschwa/src/mesos
$ git checkout master
fatal: 'master' is already checked out at '/home/andschwa/src/mesos-master'
$ fuck
cd /home/andschwa/src/mesos-master [enter/↑/↓/ctrl+c]
$ cd ~/src/mesos
$ git co master
fatal: 'master' is already checked out at '/home/andschwa/src/mesos-master'
$ fuck
cd /home/andschwa/src/mesos-master [enter/↑/↓/ctrl+c]
$ cd ~/src/mesos
$ g checkout master
fatal: 'master' is already checked out at '/home/andschwa/src/mesos-master'
$ fuck
No fucks given

It looks to me that this scenario is supposed to be supported, but I cannot get it to work. The g alias is in the output of fish -ic functions:

., N_, abbr, alias, cd, contains_seq, delete-or-exit, dirh, dirs, down-or-search, e, ec, edit_command_buffer, eval, export, extract, fish_clipboard_copy,
fish_clipboard_paste, fish_config, fish_default_key_bindings, fish_default_mode_prompt, fish_fallback_prompt, fish_greeting, fish_hybrid_key_bindings,
fish_indent, fish_key_reader, fish_md5, fish_mode_prompt, fish_prompt, fish_sigtrap_handler, fish_title, fish_update_completions, fish_vi_cursor,
fish_vi_key_bindings, fish_vi_mode, fuck, funced, funcsave, g, grep, help, history, hostname, isatty, la, ll, ls, man, math, nextd, nextd-or-forward-word,
open, p, package, popd, prevd, prevd-or-backward-word, prompt_hostname, prompt_pwd, psub, pushd, rbenv, rbt_post, rbt_update, realpath, rg, seq, setenv,
string, suspend, trap, type, umask, up-or-search, vared,

I have tried:

  • updating thefuck
  • switching to the Python 3.6 version of thefuck
  • mucking around with the THEFUCK_OVERRIDDEN_ALIASES but learned from another issue that is for the scenario of git being aliased to something else (e.g. hub)
  • restarting my shells etc. entirely
  • ensuring fish is my login shell with chsh

Issue #479 seems to be the same problem, but it went away with a newer version of Python(?) I guess.

@jberglinds
Copy link

Same issue here.
Using fish with latest thefuck.

I have git aliased to hub and it never works for git commands. Other unaliased commands seem to work.

@djh82
Copy link
Contributor

djh82 commented Jan 1, 2018

@andschwa any chance you could test my proposed change fixes your issue?

@scorphus
Copy link
Collaborator

scorphus commented Jan 3, 2018

I have git aliased to hub and it never works for git commands. Other unaliased commands seem to work.

Hi, @jberglinds! Can you please add git to the THEFUCK_OVERRIDDEN_ALIASES environment variable as instructed here and see if it works?

Thanks!

josephfrazier pushed a commit that referenced this issue Jan 3, 2018
* Handle user defined fish aliases

* Add more aliases to test

* Revert unecessary Popen mock changes

* Add test for fish aliasing

Fixes #727
riley-martine pushed a commit to riley-martine/thefuck that referenced this issue Dec 7, 2023
* Handle user defined fish aliases

* Add more aliases to test

* Revert unecessary Popen mock changes

* Add test for fish aliasing

Fixes nvbn#727
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants