blob: 8c484a2da1d270f8b100a2ddae70426a57a08fe1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env sh
# Description: Only works inside a tmux session - Opens files in Neovim.
# If $NVIM is set and its server is alive, files are opened
# in that server. Otherwise, a new pane is split on the left
# and files are opened there until the nnn pane is closed.
#
# Dependencies: tmux neovim
#
# Tip: Exec nnn inside Neovim pane via a leader key
#
# vim.keymap.set("n", "<Leader>n", function()
# if vim.env.TMUX then
# vim.fn.system({
# "tmux", "split-window", "-h",
# "-c", vim.fn.getcwd(),
# "-e", "NVIM=" .. vim.v.servername,
# "exec nnn"
# })
# end
# end)
#
# Shell: POSIX compliant
# Author: 8lackfish
fpath="${2:+$2/}$1"
if [ -n "$TMUX" ]; then
if [ -S "$NVIM" ]; then
svname="$NVIM"
nvim --server "$svname" --remote "$fpath"
else
id=$(tmux display-message -p '#{pane_id}.#{window_id}.#{session_id}' | tr -d '%@$')
svname="${XDG_RUNTIME_DIR:-/tmp}/nvim.nnn-tnp.$id"
if [ -S "$svname" ]; then
nvim --server "$svname" --remote "$fpath"
else
tmux split-pane -bdh "nvim --listen \"${svname}\" \"${fpath}\""
fi
fi
until nvim --headless --server "$svname" \
--remote-expr "execute('%argdelete')" >/dev/null 2>&1
do :; done
else
printf "\n'%s' only works inside a tmux session" "$(basename "$0")"
printf "\n\n'Enter' to return"; read -r _
fi
|