Jelajahi Sumber

fix(lazygit): use custom script to call `nvim` as `lazygit` editor

Joe 1 tahun lalu
induk
melakukan
05e1e4f7da
2 mengubah file dengan 18 tambahan dan 1 penghapusan
  1. 3 1
      .config/lazygit/config.yml
  2. 15 0
      .scripts/lazygit_nvim_editor.zsh

+ 3 - 1
.config/lazygit/config.yml

@@ -16,7 +16,9 @@ git:
     autoWrapCommitMessage: true
     autoWrapCommitMessage: true
     autoWrapWidth: 72
     autoWrapWidth: 72
 os:
 os:
-  edit: "floaterm {{filename}}"
+  edit: "$HOME/.scripts/lazygit_nvim_editor.zsh {{filename}}"
+  editAtLine: "$HOME/.scripts/lazygit_nvim_editor.zsh {{filename}} {{line}}"
+  editAtLineAndWait: "$HOME/.scripts/lazygit_nvim_editor.zsh {{filename}} {{line}}"
   editInTerminal: false
   editInTerminal: false
 refresher:
 refresher:
   refreshInterval: 2
   refreshInterval: 2

+ 15 - 0
.scripts/lazygit_nvim_editor.zsh

@@ -0,0 +1,15 @@
+#!/bin/zsh
+
+LINE=0;
+if [ -n "$2" ]; then
+    LINE=$2
+fi;
+
+if [ -n "$NVIM" ]; then
+    nvim --clean --headless --server $NVIM --remote-expr "execute(':vs $1 | $2')"
+elif [ -n "$TMUX" ]; then
+    tmux split-window "nvim +$2 $1"
+else
+    echo "Cannot edit file using $(basename $0) without \$NVIM or \$TMUX variables set";
+    exit 1;
+fi