summaryrefslogtreecommitdiff
path: root/mut/bin/vremote
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2024-04-19 17:39:16 +0200
committerMike Vink <mike@pionative.com>2024-04-19 17:39:16 +0200
commite39341f567c74f88a3610adce25d42e2a3666a91 (patch)
treef12f8cf89eea186c2a005613ff07832169da22da /mut/bin/vremote
parent985cac44e0c7b33763d0f9d26842ad5325a4a303 (diff)
update from lemptop
Diffstat (limited to 'mut/bin/vremote')
-rwxr-xr-xmut/bin/vremote50
1 files changed, 29 insertions, 21 deletions
diff --git a/mut/bin/vremote b/mut/bin/vremote
index 75b404e..4d0d417 100755
--- a/mut/bin/vremote
+++ b/mut/bin/vremote
@@ -3,31 +3,39 @@ if [ -z "$PATH" ]; then
PATH="/etc/profiles/per-user/$USER/bin:/run/current-system/sw/bin:/usr/bin:/bin"
fi
server_pipe="$XDG_CACHE_HOME/nvim/server.pipe"
+if ! [ -e "$server_pipe" ]; then
+ nohup nvim --listen "$server_pipe" --headless >/dev/null 2>&1 &
+fi
+
(
- if ! [ -e "$server_pipe" ]; then
- nohup nvim --listen "$server_pipe" --headless >/dev/null 2>&1 &
+ file_names=()
+ if [ -n "$1" ]; then
+ for file_name in "${@}"; do
+ if [[ "${file_name:0:1}" == / || "${file_name:0:2}" == ~[/a-zA-Z0-9] ]]
+ then
+ file_names+=("$file_name")
+ else
+ file_names+=("${PWD}/$file_name")
+ fi
+ done
+ echo "got file_names: ${file_names[*]}"
fi
- if nvim --headless --server ~/.cache/nvim/server.pipe --remote-expr 'luaeval("vim.json.encode(vim.iter(vim.api.nvim_list_uis()):map(function(v) return v.chan end):totable())")' \
- | jq -r '.[]' \
- | while read -r chan; do
- osascript -e 'display notification "already existing ui('"$chan"')..." with title "vremote"'
- exit 1
- done
+ if ! nvim \
+ --headless \
+ --server ~/.cache/nvim/server.pipe \
+ --remote-expr 'luaeval("vim.json.encode(vim.iter(vim.api.nvim_list_uis()):map(function(v) return v.chan end):totable())")' \
+ | jq -er '.[]'
then
- if [ -n "$1" ]; then
- file_names=()
- for file_name in "${@}"; do
- if [[ "${file_name:0:1}" == / || "${file_name:0:2}" == ~[/a-zA-Z0-9] ]]
- then
- file_names+=("$file_name")
- else
- file_names+=("${PWD}/$file_name")
- fi
- done
- echo "got file_names: ${file_names[*]}"
- nvim --server "$server_pipe" --remote "${file_names[@]}" >/dev/tty
- fi
+ nvim --server "$server_pipe" --remote "${file_names[@]}" >/dev/tty
exec nvim --server "$server_pipe" --remote-ui >/dev/tty
+ else
+ if ! command -v osascript >/dev/null 2>&1; then
+ notify-send "already existing ui
+starting new nvim instance"
+ else
+ osascript -e 'display notification "already existing ui..." with title "vremote"'
+ fi
+ exec nvim "${file_names[@]}" >/dev/tty </dev/tty
fi
) > ~/vremote_logs 2>&1