From 7ead8f459e22a942fcef516f7b107f05ccda1dbc Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 4 Jul 2018 15:09:09 +0200 Subject: [PATCH] [completions/git] Offer containing directories Fixes #5083. --- share/completions/git.fish | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/share/completions/git.fish b/share/completions/git.fish index ab28ac2e9..1259c57fd 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -111,6 +111,8 @@ function __fish_git_files contains -- copied $argv; and set -l copied and set -l copied_desc (_ "Copied file") + set -l dir_desc (_ "Directory") + # A literal "?" for use in `case`. set -l q '\\?' if status test-feature qmark-noglob @@ -231,6 +233,17 @@ function __fish_git_files set -l fromroot (builtin realpath -- $file 2>/dev/null) and set fromroot (string replace -- "$root/" ":/" "$fromroot") and printf '%s\t%s\n' "$fromroot" $desc + + # And the containing directory. + # TODO: We may want to offer the parent, but only if another child of that also has a change. + # E.g: + # - a/b/c is added + # - a/d/e is modified + # - a/ should be offered, but only a/b/ and a/d/ are. + # + # Always offering all parents is overkill however, which is why we don't currently do it. + set -l dir (string replace -rf '/[^/]+$' '/' -- $file) + and printf '%s\t%s\n' $dir "$dir_desc" end end else @@ -342,6 +355,9 @@ function __fish_git_files end set -a file (string join / -- $previous) printf '%s\n' $file\t$desc + + set -l dir (string replace -rf '/[^/]+$' '/' -- $file) + and printf '%s\t%s\n' $dir "$dir_desc" end end end