diff options
author | Fabian Homborg <FHomborg@gmail.com> | 2015-10-06 14:05:08 +0200 |
---|---|---|
committer | Fabian Homborg <FHomborg@gmail.com> | 2015-10-06 14:05:08 +0200 |
commit | b208d752e26fedc8cadd326bc2f319d4b1755ff4 (patch) | |
tree | eea25a77312d126f439d3006f1cb0f05fafe43b7 /share/completions/git.fish | |
parent | ec74479d447b7f54e59896e786243d98b6925728 (diff) |
git completion: Complete files relative to repo-root
Not for _everything_ because that causes too many options to be
generated (which is an issue for git as it is), but for modified, staged
and added files - which is where it is most useful.
Fixes #901 as far as I'm concerned.
Diffstat (limited to 'share/completions/git.fish')
-rw-r--r-- | share/completions/git.fish | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/share/completions/git.fish b/share/completions/git.fish index 76025ad1..42d1ac63 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -25,15 +25,21 @@ function __fish_git_remotes end function __fish_git_modified_files - command git ls-files -m --exclude-standard ^/dev/null + # git diff --name-only hands us filenames relative to the git toplevel + set -l root (command git rev-parse --show-toplevel) + # Print files from the current $PWD as-is, prepend all others with ":/" (relative to toplevel in git-speak) + # This is a bit simplistic but finding the lowest common directory and then replacing everything else in $PWD with ".." is a bit annoying + string replace -- "$PWD/" "" "$root/"(command git diff --name-only ^/dev/null) | string replace "$root/" ":/" end function __fish_git_staged_files - command git diff --staged --name-only ^/dev/null + set -l root (command git rev-parse --show-toplevel) + string replace -- "$PWD/" "" "$root/"(command git diff --staged --name-only ^/dev/null) | string replace "$root/" ":/" end function __fish_git_add_files - command git ls-files -mo --exclude-standard ^/dev/null + set -l root (command git rev-parse --show-toplevel) + string replace -- "$PWD/" "" "$root/"(command git -C $root ls-files -mo --exclude-standard ^/dev/null) | string replace "$root/" ":/" end function __fish_git_ranges |