From 48e91dadb53f7ac33cab238fb761b18630b6da6e Mon Sep 17 00:00:00 2001 From: sandr01d <88739791+sandr01d@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:06:30 +0200 Subject: [PATCH] Fixed opening files in the editor when a path contains spaces or a file was renamed (#323) Fixed two issues that occurred when trying to open files in the editor (ctrl+e). In both cases the wrong files were opened. 1. Files that have spaces in their path. I fixed this by properly escaping the variables used in _forgit_diff() and forgit_add(). 2. When a tracked file was renamed and added, trying to open it in the editor from the diff view, would open a file with a name that consists of both, the old and the new name. I added a separate sed command that can handle this special case. --- bin/git-forgit | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index afb14642..0db33a3d 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -138,6 +138,9 @@ _forgit_diff() { # We have to do a two-step sed -> tr pipe because OSX's sed implementation does # not support the null-character directly. get_files="echo {} | sed 's/.*] *//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" + # Similar to the line above, but only gets a single file from a single line + # Gets the new name of renamed files + get_file="echo {} | sed 's/.*] *//' | sed 's/.*-> //'" # Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}". # In order to support passing stashes as arguments to _forgit_diff, we have to # prevent fzf from interpreting this substring by escaping the opening bracket. @@ -150,7 +153,7 @@ _forgit_diff() { $FORGIT_FZF_DEFAULT_OPTS +m -0 --bind=\"enter:execute($enter_cmd | $_forgit_enter_pager)\" --preview=\"$preview_cmd\" - --bind=\"alt-e:execute-silent($EDITOR \$\($get_files\) >/dev/tty /dev/tty \" " @@ -191,7 +194,7 @@ _forgit_add() { $FORGIT_FZF_DEFAULT_OPTS -0 -m --nth 2..,.. --preview=\"$preview\" - --bind=\"alt-e:execute-silent($EDITOR \$\(echo {} | $extract\) >/dev/tty /dev/tty