From 0b7f1f47f537551677fed9fdbe5b11f714c2ce90 Mon Sep 17 00:00:00 2001 From: sandroid Date: Wed, 13 Mar 2024 21:14:03 +0100 Subject: [PATCH] Refactor: Replace _forgit_extract_sha variable with function We used to store code that extracts the commit hash from a line in a variable. This commit replaces this variable with a function. --- bin/git-forgit | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index f3bb035..8e4fbe8 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -75,7 +75,6 @@ _forgit_emojify() { } # extract the first git sha occurring in the input and strip trailing newline -_forgit_extract_sha="grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]'" _forgit_extract_sha() { grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' } @@ -556,7 +555,7 @@ _forgit_rebase() { git log "${graph[@]}" --color=always --format="$_forgit_log_format" "$@" | _forgit_emojify | FZF_DEFAULT_OPTS="$opts" fzf | - eval "$_forgit_extract_sha") + _forgit_extract_sha) if [[ -n "$target_commit" ]]; then prev_commit=$(_forgit_previous_commit "$target_commit") git rebase -i "${_forgit_rebase_git_opts[@]}" "$prev_commit" @@ -590,7 +589,7 @@ _forgit_fixup() { git log "${graph[@]}" --color=always --format="$_forgit_log_format" "$@" | _forgit_emojify | FZF_DEFAULT_OPTS="$opts" fzf | - eval "$_forgit_extract_sha") + _forgit_extract_sha) if [[ -n "$target_commit" ]] && git commit "${_forgit_fixup_git_opts[@]}" --fixup "$target_commit"; then prev_commit=$(_forgit_previous_commit "$target_commit") # rebase will fail if there are unstaged changes so --autostash is needed to temporarily stash them @@ -719,7 +718,7 @@ _forgit_checkout_commit() { [[ $_forgit_log_graph_enable == true ]] && graph=(--graph) commit="$(git log "${graph[@]}" --color=always --format="$_forgit_log_format" | _forgit_emojify | - FZF_DEFAULT_OPTS="$opts" fzf | eval "$_forgit_extract_sha")" + FZF_DEFAULT_OPTS="$opts" fzf | _forgit_extract_sha)" _forgit_git_checkout_commit "$commit" }