mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 12:28:39 +08:00
completions/git: handle 2 RM and 2 RD files
This commit makes git completions aware of files that are both staged as renamed, and have unstaged modifications/are deleted. __fish_git_files now potentially prints these files twice: $ __fish_git_files renamed modified foo Renamed file foo Modified file Fixes #6031
This commit is contained in:
parent
8baea8b157
commit
ec834820f5
|
@ -180,6 +180,24 @@ function __fish_git_files
|
|||
set -ql renamed
|
||||
and set file (string replace -r '\t[^\t]*' '' -- "$line[10..-1]")
|
||||
and set desc $renamed_desc
|
||||
case '2 RM*'
|
||||
# Staged as renamed, with unstaged modifications (issue #6031)
|
||||
set -ql renamed
|
||||
or set -ql modified
|
||||
and set file (string replace -r '\t[^\t]*' '' -- "$line[10..-1]")
|
||||
set -ql renamed
|
||||
and set desc $renamed_desc
|
||||
set -ql modified
|
||||
and set --append desc $modified_desc
|
||||
case '2 RD*'
|
||||
# Staged as renamed, but deleted in the worktree
|
||||
set -ql renamed
|
||||
or set -ql deleted
|
||||
and set file (string replace -r '\t[^\t]*' '' -- "$line[10..-1]")
|
||||
set -ql renamed
|
||||
and set desc $renamed_desc
|
||||
set -ql deleted
|
||||
and set --append desc $deleted_desc
|
||||
case '2 .C*' '2 C.*'
|
||||
set -ql copied
|
||||
and set file (string replace -r '\t[^\t].*' '' -- "$line[10..-1]")
|
||||
|
@ -261,23 +279,25 @@ function __fish_git_files
|
|||
end
|
||||
# Only try printing if the file was selected.
|
||||
if set -q file[1]
|
||||
# Without "-z", git sometimes _quotes_ filenames.
|
||||
# It adds quotes around it _and_ escapes the character.
|
||||
# e.g. `"a\\b"`.
|
||||
# We just remove the quotes and hope it works out.
|
||||
# If this contains newlines or tabs,
|
||||
# there is nothing we can do, but that's a general issue with scripted completions.
|
||||
set file (string trim -c \" -- $file)
|
||||
# First the relative filename.
|
||||
printf '%s\t%s\n' "$file" $desc
|
||||
# Now from repo root.
|
||||
# Only do this if the filename isn't a simple child,
|
||||
# or the current token starts with ":"
|
||||
if string match -q '../*' -- $file
|
||||
or string match -q ':*' -- (commandline -ct)
|
||||
set -l fromroot (builtin realpath -- $file 2>/dev/null)
|
||||
and set fromroot (string replace -- "$root/" ":/" "$fromroot")
|
||||
and printf '%s\t%s\n' "$fromroot" $desc
|
||||
for d in $desc
|
||||
# Without "-z", git sometimes _quotes_ filenames.
|
||||
# It adds quotes around it _and_ escapes the character.
|
||||
# e.g. `"a\\b"`.
|
||||
# We just remove the quotes and hope it works out.
|
||||
# If this contains newlines or tabs,
|
||||
# there is nothing we can do, but that's a general issue with scripted completions.
|
||||
set file (string trim -c \" -- $file)
|
||||
# First the relative filename.
|
||||
printf '%s\t%s\n' "$file" $d
|
||||
# Now from repo root.
|
||||
# Only do this if the filename isn't a simple child,
|
||||
# or the current token starts with ":"
|
||||
if string match -q '../*' -- $file
|
||||
or string match -q ':*' -- (commandline -ct)
|
||||
set -l fromroot (builtin realpath -- $file 2>/dev/null)
|
||||
and set fromroot (string replace -- "$root/" ":/" "$fromroot")
|
||||
and printf '%s\t%s\n' "$fromroot" $d
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user