From f0fcffa46696c55b24ed0ba057415ced7f5cc99d Mon Sep 17 00:00:00 2001 From: sandroid Date: Wed, 6 Mar 2024 22:11:35 +0100 Subject: [PATCH] Refactor: Replace deferred code in edit commands with functions _forgit_diff and _forgit_add allow editing the currently previewed file in the EDITOR. This used to be handled entirely using deferred code. This commit replaces the deferred code and binds the commands to functions instead. --- bin/git-forgit | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index bf31790..b9a6a26 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -164,6 +164,12 @@ _forgit_get_files_from_diff_line() { sed 's/.*] *//' | 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/.*] *//' | sed 's/.*-> //' +} + _forgit_exec_diff() { _forgit_diff_git_opts=() _forgit_parse_array _forgit_diff_git_opts "$FORGIT_DIFF_GIT_OPTS" @@ -184,6 +190,12 @@ _forgit_diff_view() { "$FORGIT" exec_diff "${commits[@]}" -U"$diff_context" -- | $_forgit_diff_pager } +_forgit_edit_diffed_file() { + local input_line=$1 + filename=$(echo "$input_line" | _forgit_get_single_file_from_diff_line) + $EDITOR "$filename" >/dev/tty /dev/tty \" " @@ -258,6 +267,12 @@ _forgit_get_single_file_from_add_line() { sed -e 's/^\"//' -e 's/\"$//' } +_forgit_edit_add_file() { + local input_line=$1 + filename=$(echo "$input_line" | _forgit_get_single_file_from_add_line) + $EDITOR "$filename" >/dev/tty /dev/tty