nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

commit 1da9c9fc6f98f51bc959138dab2e5a4b468b668b
parent 3b6d2adcf28b6ab88501b178d40dabc3f8d23ab0
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date:   Sun,  5 Apr 2026 19:17:22 +0530

Merge pull request #2123 from 8lackfish/tnp

Add tnp plugin
Diffstat:
Mplugins/README.md | 1+
Aplugins/tnp | 47+++++++++++++++++++++++++++++++++++++++++++++++
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