mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
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.
This commit is contained in:
parent
ec74479d44
commit
b208d752e2
1 changed files with 9 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue