commit f63647ecc3db00c55063ec6a0a6c89afa901cabb
parent 3b6d2adcf28b6ab88501b178d40dabc3f8d23ab0
Author: 8lackfish <148613625+8lackfish@users.noreply.github.com>
Date: Sun, 5 Apr 2026 16:17:14 +0700
Add tnp plugin
Diffstat:
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/plugins/README.md b/plugins/README.md
@@ -63,6 +63,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
| [rsynccp](rsynccp) | Gives copy-paste verbose progress percentage [✓] | sh | rsync |
| [splitjoin](splitjoin) | Split file or join selection [✓] | sh | split, cat |
| [suedit](suedit) | Edit file using superuser permissions | sh | sudoedit/sudo/doas |
+| [tnp](tnp) | Opens files in a Tmux Neovim pane (Tmux session only) | sh | tmux, nvim |
| [togglex](togglex) | Toggle executable mode for selection [✓] | sh | chmod |
| [umounttree](umounttree) | Unmount a remote mountpoint from within | sh | fusermount |
| [upload](upload) | Upload to Firefox Send or ix.io (text) or file.io (bin) | sh | [ffsend](https://github.com/timvisee/ffsend), curl, jq, tr |
diff --git a/plugins/tnp b/plugins/tnp
@@ -0,0 +1,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