nnn
nnn copied to clipboard
NNN does not close Tmux pane on opening a file while preview
Environment details (Put x
in the checkbox along with the information)
- [x] Operating System: Linux 6.7.4-arch1-1
- [x] Desktop Environment: Hyprland
- [x] Terminal Emulator: Kitty
- [x] Shell: zsh
- [ ] Custom desktop opener (if applicable):
- [x] Program options used:
-Adeo -Pp
- [x] Configuration options set:
export NNN_PLUG='f:finder;o:fzopen;m:mocq;d:diffs;t:nmount;v:imgview;p:preview-tui;c:fcd'
- [x] Plugins are installed
- [x] Issue exists on
nnn
master
Exact steps to reproduce the issue
- Open Kitty
- Run tmux
- Run
nnn -Adeo -Pp
(so that it starts with preview files) - Navigate to any file and press enter so that it opens vim to edit the file
The pane showing the preview is not closed on opening of vim (I did not tried to reproduce the bug with any other editor than vim).
You should try patches/restorepreview/mainline.diff. It fixed the issue for me, at least.
Looks like it does nothing in my case.
Maybe related: https://github.com/jarun/nnn/discussions/1809
I'm pretty sure restorepreview only applies to the internal editor, pressing e, enter handles it with your opener, nuke etc.
# Description: Adds preview pipe to enable closing and re-opening the preview pane when running an undetached editor.
I just copied the toggle_preview from preview_tui in a wrapper that kills the preview and uses tmux to reenable it
#!/usr/bin/env bash
TMPDIR=${TMPDIR:-/tmp} # location of temporary files
PLUG_KEY=$(echo "$NNN_PLUG" | sed 's/.*\(.\):preview-tui.*$/\1/')
NNN_PARENT=${NNN_FIFO#*.}
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
#PREVIEWPID="$TMPDIR/nnn-preview-tui-previewpid.$NNN_PARENT"
#FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
pkill() { command pkill "$@" >/dev/null 2>&1 ;}
pidkill() {
if [ -f "$1" ]; then
PID="$(cat "$1" 2>/dev/null)" || return 1
kill "$PID" >/dev/null 2>&1
RET=$?
wait "$PID" 2>/dev/null
return $RET
fi
return 1
}
run_cmd() {
if [ -n "$TMUX" ]; then
if pidkill "$FIFOPID"; then
"$@"
tmux send-keys "M-$PLUG_KEY"
else
"$@"
fi
else
"$@"
fi
return 1
}
then all you have to do to toggle it for any plugin is
source toggle_prev
run_cmd do stuff here
If you wanted it to toggle on file open you'd have to make a custom opener or edit nuke to do something similar, I just open vim in a new tmux window
Correct, the restorepreview patch hides and restores preview-tui when opening and closing an attached editor. I guess I didn't consider the case for forked programs since we don't know when it closes, or when it makes sense to restore preview-tui.
Despite that, I suppose closing preview-tui unconditionally when a file is opened can make sense as well. Not sure if it makes sense to change the restorepreview patch at this point, although I wouldn't mind it.
Since there hasn't been any response from @AinTEAsports and there has been a proposed solution I'll close this as stale.
Feel free to reopen if you want further discussion and to work on this topic.