diff options
author | lvgx <l@vgx.fr> | 2020-05-06 06:24:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 09:54:31 +0530 |
commit | f438ddc28ce30fee3f870e1a7a91e8a1e6f0845f (patch) | |
tree | 3bd762a4cefea52f47c4dfde47b4a0d016c46a3e | |
parent | 5b34d0dbe73627f8d302fc3cb6929ce87cdd286d (diff) | |
download | nnn-f438ddc28ce30fee3f870e1a7a91e8a1e6f0845f.tar.gz |
preview-tui: fix tmux behaviour, del refs to nuke (#559)
As reported by @toddyamakawa
-rwxr-xr-x | plugins/preview-tui | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/plugins/preview-tui b/plugins/preview-tui index 3efa4ac..0c50390 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -4,7 +4,7 @@ # # Note: This plugin needs a "NNN_FIFO" to work. # -# Dependencies: tmux or xterm (or set $TERMINAL), file, tree +# Dependencies: tmux (>=3.0) or xterm (or set $TERMINAL), file, tree # # How to use: # You need to set a NNN_FIFO path and set a key for the plugin, @@ -21,18 +21,14 @@ # Authors: Todd Yamakawa and Léo Villeveygoux TERMINAL="${TERMINAL:-xterm}" -NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" - -if [ ! -r "$NNN_FIFO" ] ; then - echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2 - exit 1 -fi -if [ ! -x "$NUKE" ] ; then - echo "Nuke not found!" >&2 - exit 1 -fi if [ "$PREVIEW_MODE" ] ; then + if [ ! -r "$NNN_FIFO" ] ; then + echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2 + read -r + exit 1 + fi + exec < "$NNN_FIFO" while read -r selection ; do clear @@ -40,7 +36,7 @@ if [ "$PREVIEW_MODE" ] ; then cols=$(tput cols) mime="$(file -b --mime-type "$selection")" - if [ "$mime" = "inode/directory" ] ; then + if [ -d "$selection" ]; then # Print directory tree cd "$selection" && tree | head -n $lines | cut -c 1-"$cols" elif [ "${mime%%/*}" = "text" ] ; then @@ -52,17 +48,11 @@ if [ "$PREVIEW_MODE" ] ; then file -b "$selection" fi done - - if [ -e "${TMUX%%,*}" ] ; then - tmux kill-pane - fi - exit 0 fi -if [ -e "${TMUX%%,*}" ] ; then +if [ -e "${TMUX%%,*}" ] && [ "$(tmux -V | cut -c6)" -eq 3 ] ; then tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -dh "$0" else - PREVIEW_MODE=1 GUI=0 $TERMINAL -e "$0" & + PREVIEW_MODE=1 $TERMINAL -e "$0" & fi - |