From d646d391e4aeca5685858fcb9696570d9799939c Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Sat, 6 Sep 2025 14:24:14 +0200 Subject: [PATCH] Refactor: extract function to remove status from diff line (#464) --- bin/git-forgit | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index 024988d..3ae4e51 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -232,6 +232,14 @@ _forgit_reflog() { return $fzf_exit_code } +_forgit_remove_status_from_diff_line() { + # Remove the status prefix from a diff line, e.g. + # [M] somefile + # becomes + # somefile + sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//' +} + _forgit_get_files_from_diff_line() { # Construct a null-terminated list of the filenames # The input looks like one of these lines: @@ -244,13 +252,13 @@ _forgit_get_files_from_diff_line() { # oldfile\0 # We have to do a two-step sed -> tr pipe because OSX's sed implementation does # not support the null-character directly. - sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//' | sed 's/ -> /\n/' | tr '\n' '\0' + _forgit_remove_status_from_diff_line | sed 's/ -> /\n/' | tr '\n' '\0' } _forgit_get_single_file_from_diff_line() { # Similar to the function above, but only gets a single file from a single line # Gets the new name of renamed files - sed 's/^[[:space:]]*\[[A-Z0-9]*\][[:space:]]*//' | sed 's/.*-> //' + _forgit_remove_status_from_diff_line | sed 's/.*-> //' } _forgit_exec_diff() {