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