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.
This commit is contained in:
sandroid 2024-03-13 21:14:03 +01:00
parent c2e0831110
commit 64e5353af4
No known key found for this signature in database
GPG key ID: 91418C9982B8B76E

View file

@ -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"
}