From 2b0cf3c4afae0edd9bd2446cdc15e48df16a91f5 Mon Sep 17 00:00:00 2001 From: Tim <45259958+carlfriedrich@users.noreply.github.com> Date: Sat, 18 Mar 2023 16:34:24 +0100 Subject: [PATCH] Fix temporary IFS settings (#297) When setting the IFS for a certain command only, the command must not be an assignment, otherwise both assignments are evaluated permanently (see https://unix.stackexchange.com/a/458901/317320). --- bin/git-forgit | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index 7b182f9..952028e 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -313,8 +313,10 @@ _forgit_cherry_pick() { [[ $fzf_exitval != 0 ]] && return $fzf_exitval [[ -z "$fzf_selection" ]] && return $fzf_exitval + old_IFS=$IFS IFS=$'\n' # shellcheck disable=2207 - IFS=$'\n' commits=($(echo "$fzf_selection" | sort --numeric-sort --key=1 | cut -f2 | cut -d' ' -f1 | _forgit_reverse_lines)) + commits=($(echo "$fzf_selection" | sort --numeric-sort --key=1 | cut -f2 | cut -d' ' -f1 | _forgit_reverse_lines)) + IFS=${old_IFS} [ ${#commits[@]} -eq 0 ] && return 1 $git_cherry_pick "${commits[@]}" @@ -550,13 +552,15 @@ _forgit_revert_commit() { files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command preview="echo {} | cut -f2- | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager" + old_IFS=$IFS IFS=$'\n' # shellcheck disable=2207 - IFS=$'\n' commits=($(eval "$cmd" | + commits=($(eval "$cmd" | nl | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" -m | sort --numeric-sort --key=1 | cut -f2- | sed 's/^[^a-f^0-9]*\([a-f0-9]*\).*/\1/')) + IFS=${old_IFS} [ ${#commits[@]} -eq 0 ] && return 1 @@ -602,9 +606,11 @@ _forgit_ignore() { --preview=\"eval $cmd\" $FORGIT_IGNORE_FZF_OPTS " + old_IFS=$IFS IFS=$'\n' # shellcheck disable=SC2206,2207 - IFS=$'\n' args=($@) && [[ $# -eq 0 ]] && args=($(_forgit_ignore_list | nl -nrn -w4 -s' ' | + args=($@) && [[ $# -eq 0 ]] && args=($(_forgit_ignore_list | nl -nrn -w4 -s' ' | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $2}')) + IFS=${old_IFS} [ ${#args[@]} -eq 0 ] && return 1 # shellcheck disable=SC2068 _forgit_ignore_get ${args[@]}