Implement fhackeditor, which opens or connects to an existing neovim instance
This commit is contained in:
parent
80bf43eaba
commit
f4b71c3054
9 changed files with 76 additions and 42 deletions
27
home/.scripts/fhackeditor
Executable file
27
home/.scripts/fhackeditor
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
# Script to launch a new NeoVim instance or reuse an existing one
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Settings
|
||||
SOCKET="/tmp/nvim.{{@@ env['USER'] @@}}/server.pipe"
|
||||
|
||||
# Convert each argument to absolute path
|
||||
abs_args=""
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
/*) abs="$arg" ;; # already absolute
|
||||
*) abs="$(pwd)/$arg" ;;
|
||||
esac
|
||||
abs_args="$abs_args \"$abs\""
|
||||
done
|
||||
|
||||
if [ -S "$SOCKET" ]; then
|
||||
# Pipe exists and is a socket — reuse it
|
||||
echo "Sending file to existing NeoVim instance"
|
||||
eval exec nvim --server "$SOCKET" --remote $abs_args
|
||||
else
|
||||
# Socket doesn't exist — start new instance
|
||||
exec nvim --listen "$SOCKET" "$@"
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue