From 59d3884d9687e758f0675802b6ec5819436012d0 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Tue, 26 Nov 2019 18:23:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20more=20whitespa?= =?UTF-8?q?ce=20related=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 0de4c2c91f82faf52dd4637ca3d66e5bb0f939b7 --- forgit.plugin.zsh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 5df87af..25b3a27 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -64,10 +64,11 @@ forgit::add() { " 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/' | - FZF_DEFAULT_OPTS="$opts" fzf | cut -d] -f2 | + sed 's/^\(..[^[:space:]]*\) \(.*\)$/[\1] \2/' | + FZF_DEFAULT_OPTS="$opts" fzf | + sed 's/^.*] //' | sed 's/.* -> //') # for rename case - [[ -n "$files" ]] && echo "$files" |xargs -I{} git add {} && git status --short && return + [[ -n "$files" ]] && echo "$files"| tr '\n' '\0' |xargs -0 -I{} git add {} && git status --short && return echo 'Nothing to add.' } @@ -82,7 +83,7 @@ forgit::reset::head() { $FORGIT_RESET_HEAD_FZF_OPTS " files="$(git diff --cached --name-only --relative | FZF_DEFAULT_OPTS="$opts" fzf)" - [[ -n "$files" ]] && echo "$files" |xargs -I{} git reset -q HEAD {} && git status --short && return + [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I{} git reset -q HEAD {} && git status --short && return echo 'Nothing to unstage.' } @@ -97,7 +98,7 @@ forgit::restore() { $FORGIT_CHECKOUT_FZF_OPTS " files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)" - [[ -n "$files" ]] && echo "$files" |xargs -I{} git checkout {} && git status --short && return + [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I{} git checkout {} && git status --short && return echo 'Nothing to restore.' } @@ -124,8 +125,8 @@ forgit::clean() { $FORGIT_CLEAN_FZF_OPTS " # Note: Postfix '/' in directory path should be removed. Otherwise the directory itself will not be removed. - files=$(git clean -xdfn "$@"| awk '{print $3}'| FZF_DEFAULT_OPTS="$opts" fzf |sed 's#/$##') - [[ -n "$files" ]] && echo "$files" |xargs -I% git clean -xdf % && return + files=$(git clean -xdfn "$@"| sed 's/^Would remove //' | FZF_DEFAULT_OPTS="$opts" fzf |sed 's#/$##') + [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I% git clean -xdf '%' && return echo 'Nothing to clean.' } From fdec1c9f813ea5721ab8ef274f71f5b949417830 Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Tue, 26 Nov 2019 18:42:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=F0=9F=92=84=20refactor=20xargs=20?= =?UTF-8?q?parameter=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 779e8b4d362094c2590d06d99f219eb2315329ae --- forgit.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 25b3a27..70142b7 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -68,7 +68,7 @@ forgit::add() { FZF_DEFAULT_OPTS="$opts" fzf | sed 's/^.*] //' | sed 's/.* -> //') # for rename case - [[ -n "$files" ]] && echo "$files"| tr '\n' '\0' |xargs -0 -I{} git add {} && git status --short && return + [[ -n "$files" ]] && echo "$files"| tr '\n' '\0' |xargs -0 -I% git add % && git status --short && return echo 'Nothing to add.' } @@ -83,7 +83,7 @@ forgit::reset::head() { $FORGIT_RESET_HEAD_FZF_OPTS " files="$(git diff --cached --name-only --relative | FZF_DEFAULT_OPTS="$opts" fzf)" - [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I{} git reset -q HEAD {} && git status --short && return + [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I% git reset -q HEAD % && git status --short && return echo 'Nothing to unstage.' } @@ -98,7 +98,7 @@ forgit::restore() { $FORGIT_CHECKOUT_FZF_OPTS " files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)" - [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I{} git checkout {} && git status --short && return + [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | xargs -0 -I% git checkout % && git status --short && return echo 'Nothing to restore.' }