From 07f7e4350b96fe401258f4a63e2a9df8bdb131f8 Mon Sep 17 00:00:00 2001 From: sandr01d <88739791+sandr01d@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:01:56 +0100 Subject: [PATCH] Fix diff preview and edit for files with a ']' character in their name (#354) Our sed command for removing the short status (e.g. [M]) from gits output to extract the file name with _forgit_diff matched until the last ']' character in the line due to sed being greedy. This created issues with file names that contain a ']' character. To fix this, I made sure that only the short status is removed by sed, independently of the file name. --- bin/git-forgit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index 9a876a8..3b46d04 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -137,10 +137,10 @@ _forgit_diff() { # oldfile\0 # 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'" + get_files="echo {} | sed 's/\\\\s*\\\\[.]\\\\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/.*-> //'" + get_file="echo {} | sed 's/\\\\s*\\\\[.]\\\\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.