Skip to content

Commit 48e91da

Browse files
authored
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.
1 parent e8e3083 commit 48e91da

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bin/git-forgit

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ _forgit_diff() {
138138
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does
139139
# not support the null-character directly.
140140
get_files="echo {} | sed 's/.*] *//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'"
141+
# Similar to the line above, but only gets a single file from a single line
142+
# Gets the new name of renamed files
143+
get_file="echo {} | sed 's/.*] *//' | sed 's/.*-> //'"
141144
# Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}".
142145
# In order to support passing stashes as arguments to _forgit_diff, we have to
143146
# prevent fzf from interpreting this substring by escaping the opening bracket.
@@ -150,7 +153,7 @@ _forgit_diff() {
150153
$FORGIT_FZF_DEFAULT_OPTS
151154
+m -0 --bind=\"enter:execute($enter_cmd | $_forgit_enter_pager)\"
152155
--preview=\"$preview_cmd\"
153-
--bind=\"alt-e:execute-silent($EDITOR \$\($get_files\) >/dev/tty </dev/tty)+refresh-preview\"
156+
--bind=\"alt-e:execute-silent($EDITOR \\\"\$\($get_file)\\\" >/dev/tty </dev/tty)+refresh-preview\"
154157
$FORGIT_DIFF_FZF_OPTS
155158
--prompt=\"$commits > \"
156159
"
@@ -191,7 +194,7 @@ _forgit_add() {
191194
$FORGIT_FZF_DEFAULT_OPTS
192195
-0 -m --nth 2..,..
193196
--preview=\"$preview\"
194-
--bind=\"alt-e:execute-silent($EDITOR \$\(echo {} | $extract\) >/dev/tty </dev/tty)+refresh-preview\"
197+
--bind=\"alt-e:execute-silent($EDITOR \\\"\$\(echo {} | $extract\)\\\" >/dev/tty </dev/tty)+refresh-preview\"
195198
$FORGIT_ADD_FZF_OPTS
196199
"
197200
files=$(git -c color.status=always -c status.relativePaths=true status -su |

0 commit comments

Comments
 (0)