Merge pull request #62 from cjappl/fix_path_fish

Fix path fish

Former-commit-id: 23f30e9c7a
This commit is contained in:
Chris Apple 2019-11-26 09:49:26 +01:00 committed by GitHub
commit 999cdbe0c8

View file

@ -16,11 +16,11 @@ end
set core_pager (git config core.pager)
if test -n $core_pager
set forgit_pager (echo "| $core_pager")
set forgit_pager "$core_pager"
else if type -q diff-so-fancy >/dev/null 2>&1
set forgit_pager "| diff-so-fancy | less --tabs 4 -RFX"
set forgit_pager "diff-so-fancy | less --tabs 4 -RFX"
else
set forgit_pager "| cat"
set forgit_pager "cat"
end
# https://github.com/wfxr/emoji-cli
@ -29,7 +29,8 @@ type -q emojify >/dev/null 2>&1 && set forgit_emojify '|emojify'
# git commit viewer
function forgit::log
forgit::inside_work_tree || return 1
set cmd "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % $argv $forgit_pager"
set cmd "echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % $argv | $forgit_pager"
echo $cmd
if test -n "$FORGIT_COPY_CMD"
set copy_cmd $FORGIT_COPY_CMD
@ -60,17 +61,19 @@ function forgit::diff
end
end
set cmd "git diff --color=always $commit -- {} $forgit_pager"
set repo "(git rev-parse --show-toplevel)"
set target "\(echo {} | sed 's/.*] //')"
set cmd "git diff --color=always $commit -- $repo/$target | $forgit_pager"
set opts "
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --preview=\"$cmd\" --bind=\"enter:execute($cmd |env LESS='-R' less)\"
$FORGIT_DIFF_FZF_OPTS
"
set cmd "echo" && type -q realpath > /dev/null 2>&1 && set cmd "realpath --relative-to=."
#eval "git diff --name-only $commit -- ${files[*]}| xargs -I% $cmd '(git rev-parse --show-toplevel)/%'"|
set git_rev_parse (git rev-parse --show-toplevel)
eval "git diff --name-only $commit -- $files*| xargs -I% $cmd '$git_rev_parse/%'"|
env FZF_DEFAULT_OPTS="$opts" fzf
eval "git diff --name-only $commit -- $files*| sed 's/^\(.\)[[:space:]]\+\(.*\)\$/[\1] \2/'" |
env FZF_DEFAULT_OPTS="$opts" fzf
end
# git add selector
@ -83,17 +86,22 @@ function forgit::add
set opts "
$FORGIT_FZF_DEFAULT_OPTS
-0 -m --nth 2..,..
--preview=\"git diff --color=always -- {-1} $forgit_pager\"
--preview=\"git diff --color=always -- {-1} | $forgit_pager\"
$FORGIT_ADD_FZF_OPTS
"
set files (git -c color.status=always -c status.relativePaths=true status --short |
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
awk '{printf "[%10s] ", $1; $1=""; print $0}' |
env FZF_DEFAULT_OPTS="$opts" fzf | cut -d] -f2 |
sed 's/^\(..[^[:space:]]*\)[[:space:]]\+\(.*\)\$/[\1] \2/' | # deal with white spaces internal to fname
env FZF_DEFAULT_OPTS="$opts" fzf |
sed -e '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
if test -n "$files"
echo $files | tr ' ' '\n' |xargs -I{} git add {} && git status --short && return
for file in $files
echo $file | tr '\n' '\0' | xargs -I{} -0 git add {} && git status --short && return
end
return
end
echo 'Nothing to add.'
end
@ -101,7 +109,7 @@ end
## git reset HEAD (unstage) selector
function forgit::reset::head
forgit::inside_work_tree || return 1
set cmd "git diff --cached --color=always -- {} $forgit_pager"
set cmd "git diff --cached --color=always -- {} | $forgit_pager"
set opts "
$FORGIT_FZF_DEFAULT_OPTS
-m -0 --preview=\"$cmd\"
@ -109,7 +117,9 @@ function forgit::reset::head
"
set files (git diff --cached --name-only --relative | env FZF_DEFAULT_OPTS="$opts" fzf)
if test -n "$files"
echo $files | tr ' ' '\n' |xargs -I{} git reset -q HEAD {} && git status --short && return
for file in $files
echo $file | tr '\n' '\0' |xargs -I{} -0 git reset -q HEAD {} && git status --short && return
end
end
echo 'Nothing to unstage.'
end
@ -118,7 +128,7 @@ end
function forgit::restore
forgit::inside_work_tree || return 1
set cmd "git diff --color=always -- {} $forgit_pager"
set cmd "git diff --color=always -- {} | $forgit_pager"
set opts "
$FORGIT_FZF_DEFAULT_OPTS
-m -0 --preview=\"$cmd\"
@ -127,7 +137,9 @@ function forgit::restore
set git_rev_parse (git rev-parse --show-toplevel)
set files (git ls-files --modified "$git_rev_parse" | env FZF_DEFAULT_OPTS="$opts" fzf)
if test -n "$files"
echo $files | tr ' ' '\n' |xargs -I{} git checkout {} && git status --short && return
for file in $files
echo $file | tr '\n' '\0' |xargs -I{} -0 git checkout {} && git status --short && return
end
end
echo 'Nothing to restore.'
end
@ -135,7 +147,7 @@ end
# git stash viewer
function forgit::stash::show
forgit::inside_work_tree || return 1
set cmd "git stash show \(echo {}| cut -d: -f1) --color=always --ext-diff $forgit_pager"
set cmd "git stash show \(echo {}| cut -d: -f1) --color=always --ext-diff | $forgit_pager"
set opts "
$FORGIT_FZF_DEFAULT_OPTS
+s +m -0 --tiebreak=index --preview=\"$cmd\" --bind=\"enter:execute($cmd |env LESS='-R' less)\"
@ -157,7 +169,9 @@ function forgit::clean
set files (git clean -xdfn $argv| awk '{print $3}'| env FZF_DEFAULT_OPTS="$opts" fzf |sed 's#/$##')
if test -n "$files"
echo $files | tr ' ' '\n'|xargs -I{} git clean -xdf {} && return
for file in $files
echo $file | tr '\n' '\0'|xargs -0 -I{} git clean -xdf {} && return
end
end
echo 'Nothing to clean.'
end