wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.4k stars 137 forks source link

forgit add doesn't preview properly when user shell is bash and interactive shell is fish #168

Closed p00f closed 2 years ago

p00f commented 2 years ago

Check list

Environment info

Problem / Steps to reproduce

When I use ga, the preview doesn't work

image

This is because my user shell is bash and my interactive shell is fish. (This was necessary because fish can't read system config files: https://wiki.archlinux.org/title/Fish#Setting_fish_as_default_shell). fzf uses bash to interpret $preview which won't work because it is fish syntax.

The fix is to use fish to interpret $preview like so:

--- forgit_fix.fish 2021-11-26 09:33:13.403016477 +0530
+++ .config/fish/conf.d/forgit.plugin.fish  2021-11-26 09:33:47.813758484 +0530
@@ -102,12 +102,12 @@
     set preview "
         set file (echo {} | $extract_file)
         # exit
-        if test (git status -s -- \\\$file | grep '^??') # diff with /dev/null for untracked files
-            git diff --color=always --no-index -- /dev/null \\\$file | $forgit_diff_pager | sed '2 s/added:/untracked:/'
+        if test (git status -s -- \$file | grep '^??') # diff with /dev/null for untracked files
+            git diff --color=always --no-index -- /dev/null \$file | $forgit_diff_pager | sed '2 s/added:/untracked:/'
         else
-            git diff --color=always -- \\\$file | $forgit_diff_pager
+            git diff --color=always -- \$file | $forgit_diff_pager
         end
-    "
+        "
     set opts "
         $FORGIT_FZF_DEFAULT_OPTS
         -0 -m --nth 2..,..
@@ -116,7 +116,7 @@
     set files (git -c color.status=always -c status.relativePaths=true status -su |
         grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
         sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)\$/[\1]  \2/' |   # deal with white spaces internal to fname
-        env FZF_DEFAULT_OPTS="$opts" fzf --preview="fish -c \"$preview\"" |
+        env FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" |
         sh -c "$extract_file") # for rename case

     if test -n "$files"
@@ -544,3 +544,4 @@
     end

 end
+

This fixes the issue:

image

p00f commented 2 years ago

Whoops this is a dupe of #152

p00f commented 2 years ago

I'll leave this open because having the user shell as bash is a genuine use case and #152 has been closed, feel free to close it and move the discussion there.

cc @Araly

Araly commented 2 years ago

I'll leave this open because having the user shell as bash is a genuine use case and #152 has been closed, feel free to close it and move the discussion there.

cc @Araly

I've been using lazygit for now, but I can try to test ga with the fix at work later next week

p00f commented 2 years ago

@wfxr do you want me to make a PR?

p00f commented 2 years ago

see #169