mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
Fish: Fix GA and GD when there is whitespace in the name (#209)
This commit is contained in:
parent
fdd5632b17
commit
6ce2c25490
|
|
@ -72,6 +72,16 @@ function forgit::log -d "git commit viewer"
|
|||
env FZF_DEFAULT_OPTS="$opts" fzf
|
||||
end
|
||||
|
||||
function forgit::extract_file --argument-names 'path'
|
||||
set no_leading_whitespace (echo $path | sed 's/^[[:space:]]*//')
|
||||
set no_m_or_double_question (echo $no_leading_whitespace | cut -d ' ' -f 2-)
|
||||
set if_renamed (echo $no_m_or_double_question | sed 's/.* -> //')
|
||||
set no_quotes (echo $if_renamed | tr -d "\"")
|
||||
set no_leading_whitespace_again (echo $no_quotes | sed 's/^[[:space:]]*//')
|
||||
set no_spaces (echo $no_leading_whitespace_again | string escape --no-quoted)
|
||||
echo $no_spaces
|
||||
end
|
||||
|
||||
## git diff viewer
|
||||
function forgit::diff -d "git diff viewer" --argument-names arg1 arg2
|
||||
forgit::inside_work_tree || return 1
|
||||
|
|
@ -88,8 +98,7 @@ function forgit::diff -d "git diff viewer" --argument-names arg1 arg2
|
|||
end
|
||||
end
|
||||
|
||||
set repo (git rev-parse --show-toplevel)
|
||||
set preview "cd '$repo' && echo {} | sed 's/.*] *//' | sed 's/ -> / /' | xargs git diff --color=always $commits -- | $forgit_diff_pager"
|
||||
set preview "forgit::extract_file {} | xargs git diff --color=always $commits -- | $forgit_diff_pager"
|
||||
|
||||
set opts "
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
|
|
@ -116,14 +125,8 @@ function forgit::add -d "git add selector"
|
|||
set unmerged (git config --get-color color.status.unmerged red)
|
||||
set untracked (git config --get-color color.status.untracked red)
|
||||
|
||||
set extract_file "
|
||||
sed 's/^[[:space:]]*//' | # remove leading whitespace
|
||||
cut -d ' ' -f 2- | # cut the line after the M or ??, this leaves just the filename
|
||||
sed 's/.* -> //' # for rename case
|
||||
"
|
||||
|
||||
set preview "
|
||||
set file (echo {} | $extract_file)
|
||||
set file (forgit::extract_file {})
|
||||
# exit
|
||||
if test (git status -s -- \$file | grep '^??') # diff with /dev/null for untracked files
|
||||
git diff --color=always --no-index -- /dev/null \$file | $forgit_diff_pager | sed '2 s/added:/untracked:/'
|
||||
|
|
@ -140,12 +143,13 @@ function forgit::add -d "git add selector"
|
|||
set files (git -c color.status=always -c status.relativePaths=true status -su |
|
||||
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
|
||||
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)\$/[\1] \2/' | # deal with white spaces internal to fname
|
||||
env FZF_DEFAULT_OPTS="$opts" fzf |
|
||||
sh -c "$extract_file") # for rename case
|
||||
env FZF_DEFAULT_OPTS="$opts" fzf
|
||||
)
|
||||
|
||||
if test -n "$files"
|
||||
for file in $files
|
||||
echo $file | tr '\n' '\0' | xargs -I{} -0 git add {}
|
||||
set stripped_file (forgit::extract_file $file)
|
||||
echo $stripped_file | tr '\n' '\0' | xargs -I{} -0 git add {}
|
||||
end
|
||||
git status --short
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue