From 4adb512b59cee08060f73c464a63875a66135cc5 Mon Sep 17 00:00:00 2001 From: sandroid Date: Fri, 26 Jan 2024 10:10:58 +0100 Subject: [PATCH 1/2] Remove usage of --pathspec-from-file and --pathspec-file-nul --- bin/git-forgit | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index 2db6d77e..66f53c50 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -326,12 +326,12 @@ _forgit_add() { --bind=\"alt-e:execute-silent($FORGIT edit_add_file {})+refresh-preview\" $FORGIT_ADD_FZF_OPTS " - files=$(git -c color.status=always -c status.relativePaths=true status -su | + read -r -a 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/' | FZF_DEFAULT_OPTS="$opts" fzf | - _forgit_get_single_file_from_add_line) - [[ -n "$files" ]] && echo "$files"| tr '\n' '\0' | _forgit_git_add --pathspec-file-nul --pathspec-from-file - && git status -su && return + _forgit_get_single_file_from_add_line)" + [[ "${#files[@]}" -gt 0 ]] && _forgit_git_add "${files[@]}" && git status -su && return echo 'Nothing to add.' } @@ -442,9 +442,9 @@ _forgit_stash_push() { $FORGIT_STASH_PUSH_FZF_OPTS " # Show both modified and untracked files - files=$(git ls-files --exclude-standard --modified --others | FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}") - [[ -z "$files" ]] && return 1 - echo "${files[@]}" | tr '\n' '\0' | _forgit_git_stash_push ${msg:+-m "$msg"} -u --pathspec-file-nul --pathspec-from-file - + read -r -a files <<< "$(git ls-files --exclude-standard --modified --others | FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}")" + [[ "${#files[@]}" -eq 0 ]] && return 1 + _forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}" } # git clean selector @@ -636,8 +636,8 @@ _forgit_checkout_file() { --preview=\"$FORGIT checkout_file_preview {}\" $FORGIT_CHECKOUT_FILE_FZF_OPTS " - files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)" - [[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | _forgit_git_checkout_file --pathspec-file-nul --pathspec-from-file - + read -r -a files <<< "$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)" + [[ "${#files[@]}" -gt 0 ]] && _forgit_git_checkout_file "${files[@]}" } _forgit_git_checkout_branch() { From 937a21c8f1898414d97fe8c55e4829e8c0cd81a7 Mon Sep 17 00:00:00 2001 From: sandroid Date: Sun, 24 Mar 2024 16:51:18 +0100 Subject: [PATCH 2/2] Fix executing commands on multiple files --- bin/git-forgit | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index 66f53c50..5170e679 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -326,11 +326,14 @@ _forgit_add() { --bind=\"alt-e:execute-silent($FORGIT edit_add_file {})+refresh-preview\" $FORGIT_ADD_FZF_OPTS " - read -r -a files <<< "$(git -c color.status=always -c status.relativePaths=true status -su | + files=() + while IFS='' read -r file; do + files+=("$file") + done < <(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/' | FZF_DEFAULT_OPTS="$opts" fzf | - _forgit_get_single_file_from_add_line)" + _forgit_get_single_file_from_add_line) [[ "${#files[@]}" -gt 0 ]] && _forgit_git_add "${files[@]}" && git status -su && return echo 'Nothing to add.' } @@ -442,7 +445,11 @@ _forgit_stash_push() { $FORGIT_STASH_PUSH_FZF_OPTS " # Show both modified and untracked files - read -r -a files <<< "$(git ls-files --exclude-standard --modified --others | FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}")" + files=() + while IFS='' read -r file; do + files+=("$file") + done < <(git ls-files --exclude-standard --modified --others | + FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}") [[ "${#files[@]}" -eq 0 ]] && return 1 _forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}" } @@ -636,7 +643,11 @@ _forgit_checkout_file() { --preview=\"$FORGIT checkout_file_preview {}\" $FORGIT_CHECKOUT_FILE_FZF_OPTS " - read -r -a files <<< "$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)" + files=() + while IFS='' read -r file; do + files+=("$file") + done < <(git ls-files --modified "$(git rev-parse --show-toplevel)" | + FZF_DEFAULT_OPTS="$opts" fzf) [[ "${#files[@]}" -gt 0 ]] && _forgit_git_checkout_file "${files[@]}" }