From 0ab437be2601bb4100aee1138d3af3d4faade55d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 29 Jan 2018 19:05:42 +0100 Subject: [PATCH] [git completions] Make paths not in $PWD relative to the root again When git prints a path like "share/completions/git.fish", that's relative to the root of the repo. So we need to either remove everything from the $PWD (if the path is inside the $PWD), or prepend a ":/", which is git-speak for "relative to the root". This was removed by mistake in the recent switch to `git status`. Fixes #4688. --- share/completions/git.fish | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index f1cca7ba0..36c83b522 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -83,6 +83,9 @@ function __fish_git_files # and as a convenience "all-staged" # to get _all_ kinds of staged files. + # Save the repo root to remove it from the path later. + set -l root (command git rev-parse --show-toplevel ^/dev/null) + # git status --porcelain gives us all the info we need, in a format we don't. # The v2 format has better documentation and doesn't use " " to denote anything, # but it's only been added in git 2.11.0, which was released November 2016. @@ -98,7 +101,7 @@ function __fish_git_files # The entire line is the "from" from a rename. if set -q use_next[1] contains -- $use_next $argv - and echo "$line" + and string replace -- "$PWD/" "" "$root/$line" | string replace "$root/" ":/" set -e use_next[1] continue end @@ -110,6 +113,9 @@ function __fish_git_files set -l IFS set -l stat (string sub -l 2 -- $line) set -l file (string sub -s 4 -- $line) + # 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 + set file (string replace -- "$PWD/" "" "$root/$file" | string replace "$root/" ":/") set -e IFS # The basic status format is "XY", where X is "our" state (meaning the staging area),