diff options
Diffstat (limited to 'files/.config/nnn/plugins/preview-tabbed')
| -rwxr-xr-x | files/.config/nnn/plugins/preview-tabbed | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/files/.config/nnn/plugins/preview-tabbed b/files/.config/nnn/plugins/preview-tabbed index 5235c1e..2493fdf 100755 --- a/files/.config/nnn/plugins/preview-tabbed +++ b/files/.config/nnn/plugins/preview-tabbed @@ -4,7 +4,7 @@ # # Dependencies: # - tabbed (https://tools.suckless.org/tabbed): xembed host -# - xterm (or urxvt or st) : xembed client for text-based preview +# - xterm (or urxvt or st or alacritty) : xembed client for text-based preview # - mpv (https://mpv.io): xembed client for video/audio # - sxiv (https://github.com/muennich/sxiv) or, # - nsxiv (https://codeberg.org/nsxiv/nsxiv) : xembed client for images @@ -57,16 +57,21 @@ if [ -n "$WAYLAND_DISPLAY" ] ; then exit 1 fi -if type xterm >/dev/null 2>&1 ; then - TERMINAL="xterm -into" -elif type urxvt >/dev/null 2>&1 ; then - TERMINAL="urxvt -embed" +if type alacritty >/dev/null 2>&1 ; then + TERMINAL="alacritty --embed" elif type st >/dev/null 2>&1 ; then TERMINAL="st -w" +elif type urxvt >/dev/null 2>&1 ; then + TERMINAL="urxvt -embed" +elif type xterm >/dev/null 2>&1 ; then + TERMINAL="xterm -into" else echo "No xembed term found" >&2 fi +if type xdg-user-dir >/dev/null 2>&1 ; then + PICTURES_DIR=$(xdg-user-dir PICTURES) +fi term_nuke () { # $1 -> $XID, $2 -> $FILE @@ -90,7 +95,7 @@ start_tabbed () { read -r XID < "$FIFO" - rm "$FIFO" + rm -- "$FIFO" } get_viewer_pid () { @@ -175,7 +180,17 @@ previewer_loop () { fi ;; inode/directory) - $TERMINAL "$XID" -e nnn "$FILE" & + if [[ -n $PICTURES_DIR && "$FILE" == "$PICTURES_DIR"* ]] ; then + if type sxiv >/dev/null 2>&1 ; then + sxiv -te "$XID" "$FILE" & + elif type nsxiv >/dev/null 2>&1 ; then + nsxiv -te "$XID" "$FILE" & + else + $TERMINAL "$XID" -e nnn "$FILE" & + fi + else + $TERMINAL "$XID" -e nnn "$FILE" & + fi ;; text/*) if [ -x "$NUKE" ] ; then @@ -189,7 +204,8 @@ previewer_loop () { if [ -x "$NUKE" ] ; then term_nuke "$XID" "$FILE" else - $TERMINAL "$XID" -e sh -c "file '$FILE' | $PAGER -" & + SAFE_FILE=$(printf "%s" "$FILE" | sed "s/'/'\\\\''/g") + $TERMINAL "$XID" -e sh -c "file '$SAFE_FILE' | $PAGER -" & fi ;; esac |
