Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Git alias parsing breaks on shell aliases #5412
Most of my git aliases do not support tab completion.
I use several git aliases that are scripts instead of just a shortening of a git command. This breaks the git alias parsing in
It's pretty easy to illustrate the problem using the following:
$ git config --global alias.br "!echo \"A wacky alias\" && echo \"More wackiness\"" $ git br A wacky alias More wackiness $ git config -z --get-regexp 'alias\..*' | while read -lz alias command _ echo $alias echo $command end alias.br !echo
As you can see it seems to split on the whitespace in the alias and then comes out with just the first part. I've been overriding it by doing
Lastly, I can't disable/override the git alias parsing as that isn't guarded by an flag check.
I'd be happy to work up a PR if anyone is willing to give me some guidance/ideas on how to address this. :)
OS: macOS 10.14
Possibly relevant (but I haven't changed this):
I haven't reproduced this in a pristine shell because, but I have broken down the relevant parts of
added a commit
Dec 13, 2018
Sorry folks, I was wrong. The part I changed was the "this git alias corresponds to this command" bit, which should be kept as-is.
What's broken here, I assume is the "show git aliases with what they execute" bit, which is done later: https://github.com/fish-shell/fish-shell/blob/master/share/completions/git.fish#L497-L504. Because that uses newlines to delimit it, fish will become confused if there is any alias with multiple lines in the value.
That's also simple enough to solve, but my original "fix" needs to be reverted.
Would it be possible to put this feature behind a flag? I applied your fix locally and realized it doesn’t solve my problem either. :-)
What I want is to have the shell understand that
Ultimately I would rather Fish shell not try at all, or at least check if there is already an existing variable for hmthat alias and not create one in those situations.
I'm still not quite sure why that would be a problem?
Can you upload your aliases somewhere, so that I can have a look?
Or what does
We try not to do that. If you want, you can copy the git completions and make the changes you want locally. See $fish_complete_path.
Here's an example of the
In the original case,
I'm fine making a copy. Is there a way to disable the git completions that ship with the shell (I'm installing via Homebrew)?
Ah, okay. That's unparsable for us.
Here's what we're gonna do: We can't do anything with
git config -z --get-regexp 'alias\..*' | while read -lz alias command _ # If the command starts with a "!", it's a shell command, run with /bin/sh, # or any other shell defined at git's build time. # # We can't do anything with them, and we run git-config again for listing aliases, # so we skip them here. string match -q '!*' -- $command; and continue # Git aliases can contain chars that variable names can't - escape them. set alias (string replace 'alias.' '' -- $alias | string escape --style=var) set -g __fish_git_alias_$alias $command end
That means to complete them you'd have to
Like I said: $fish_complete_path. When fish loads a completion, it goes through the elements of that for a file named "command.fish", and loads the first one it finds (like $PATH).
By default, it should already have an entry ~/.config/fish/completions. Just copy the default completions (in e.g. /usr/local/share/fish/completions/) there and make your changes.