From 2670b6e69b1d12547c554741229497df094993b9 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Mon, 25 Nov 2019 23:59:45 +0100 Subject: [PATCH 1/3] first attempt at new commands, removed pipe from pager command to be more readable Former-commit-id: bd14e559e5463796758c8c8c8bf6ba658fc97217 --- forgit.plugin.fish | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/forgit.plugin.fish b/forgit.plugin.fish index 5991f90..9a707b8 100755 --- a/forgit.plugin.fish +++ b/forgit.plugin.fish @@ -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,22 @@ 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/.*] //')" + # TODO: remove pipe from front of forget_pager + set cmd "git diff --color=always $commit -- $repo/$target | $forgit_pager" + echo $cmd + exit 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,7 +89,7 @@ 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 | @@ -101,7 +107,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\" @@ -118,7 +124,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\" @@ -135,7 +141,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)\" From 050db8b7cd5edfa3be4f984a6057738871b81e0e Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Tue, 26 Nov 2019 09:35:33 +0100 Subject: [PATCH 2/3] Better way to do spaces in filenames Former-commit-id: 803cb4fd2dcc972ded146c17d992395a982b82ee --- forgit.plugin.fish | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/forgit.plugin.fish b/forgit.plugin.fish index 9a707b8..51f8357 100755 --- a/forgit.plugin.fish +++ b/forgit.plugin.fish @@ -63,10 +63,7 @@ function forgit::diff set repo "(git rev-parse --show-toplevel)" set target "\(echo {} | sed 's/.*] //')" - # TODO: remove pipe from front of forget_pager set cmd "git diff --color=always $commit -- $repo/$target | $forgit_pager" - echo $cmd - exit set opts " $FORGIT_FZF_DEFAULT_OPTS +m -0 --preview=\"$cmd\" --bind=\"enter:execute($cmd |env LESS='-R' less)\" @@ -94,12 +91,15 @@ function forgit::add " 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/' | + env FZF_DEFAULT_OPTS="$opts" fzf | cut -d " " -f 2- | 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 From 4586b34e610acabeabc4f4c10a46fe1eb4bc5d10 Mon Sep 17 00:00:00 2001 From: Christopher Apple Date: Tue, 26 Nov 2019 09:43:36 +0100 Subject: [PATCH 3/3] fixed add even more, leading whitespace issue Former-commit-id: fd63265fe5ea22abef81777c59d3bfc24e3026e4 --- forgit.plugin.fish | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/forgit.plugin.fish b/forgit.plugin.fish index 51f8357..47b0b02 100755 --- a/forgit.plugin.fish +++ b/forgit.plugin.fish @@ -91,13 +91,15 @@ function forgit::add " set files (git -c color.status=always -c status.relativePaths=true status --short | grep -F -e "$changed" -e "$unmerged" -e "$untracked" | - sed 's/^\(..[^[:space:]]*\)[[:space:]]\+\(.*\)\$/[\1] \2/' | - env FZF_DEFAULT_OPTS="$opts" fzf | cut -d " " -f 2- | + 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" for file in $files - echo $file | tr "\n" "\0" | xargs -I{} -0 git add {} && git status --short && return + echo $file | tr '\n' '\0' | xargs -I{} -0 git add {} && git status --short && return end return end @@ -115,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 @@ -133,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 @@ -163,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