Skip to content

Instantly share code, notes, and snippets.

@SamuelDavis
Last active August 2, 2026 03:25
Show Gist options
  • Select an option

  • Save SamuelDavis/17c151569772cd76be26b9bcb21aff18 to your computer and use it in GitHub Desktop.

Select an option

Save SamuelDavis/17c151569772cd76be26b9bcb21aff18 to your computer and use it in GitHub Desktop.
Start Nvim for Godot; when opening a .gd file in Godot, defer to either a running instance of Neovim if it exists, or a new one.
#!/usr/bin/env bash
set -euo pipefail
exec 2>>"/tmp/godot-nvim.log"
SOCK="${XDG_RUNTIME_DIR:-/tmp}/godot-nvim.sock"
FILE="${1:-}"
FILE="$(realpath -- "$FILE")"
LINE="${2:-1}"
COL="${3:-1}"
if [ ! -f "$FILE" ]; then
echo "usage: $(basename "$0") <file> [line] [col]" >&2
exit 1
fi
nvim_is_alive() {
[ -S "$SOCK" ] && timeout 1 nvim --server "$SOCK" --remote-expr '1' >/dev/null 2>&1
}
send_to_nvim() {
nvim --server "$SOCK" --remote-silent "$FILE"
nvim --server "$SOCK" --remote-send "<C-\\><C-n>:call cursor(${LINE}, ${COL})<CR>zvzz"
}
launch_terminal() {
local term="${TERMINAL:-}"
if [ -z "$term" ]; then
for t in cosmic-term foot kitty alacritty xterm; do
command -v "$t" >/dev/null 2>&1 && { term="$t"; break; }
done
fi
[ -n "$term" ] || { echo "godot-nvim: no terminal found; set \$TERMINAL" >&2; exit 1; }
case "$(basename "$term")" in
kitty|foot) "$term" nvim --listen "$SOCK" -c 'set title titlestring=GVim' ;;
*) "$term" -e nvim --listen "$SOCK" -c 'set title titlestring=GVim' ;;
esac >/dev/null 2>&1 &
disown
}
if nvim_is_alive; then
send_to_nvim
exit 0
fi
rm -f "$SOCK"
launch_terminal
for _ in $(seq 1 50); do
nvim_is_alive && break
sleep 0.1
done
if ! nvim_is_alive; then
echo "godot-nvim: nvim never started listening on $SOCK" >&2
exit 1
fi
send_to_nvim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment