From d85c23c433cd5ff07fc5a1d5210d1d63a608a572 Mon Sep 17 00:00:00 2001 From: Daniel Bretoi Date: Thu, 12 Sep 2024 22:15:18 -0700 Subject: [PATCH 1/4] Update preview-tui make NNN_PREVIEWIMGPROG flexible enough to accept any program. programs like `timg` would also work (my preference), but it seems odd to add every single program out there when it's easy to add new ones by just this one variable --- plugins/preview-tui | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/preview-tui b/plugins/preview-tui index 860a93a04..200d3e33f 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -460,6 +460,8 @@ image_preview() { chafa "$3" & elif exists img2sixel && [[ "$NNN_PREVIEWIMGPROG" == +(|img2sixel) ]]; then img2sixel -g "$3" & + elif exists "$NNN_PREVIEWIMGPROG"; then + "$NNN_PREVIEWIMGPROG" "$3" & else fifo_pager print_bin_info "$3" && return fi From ef1ef5646118bbb76978636033483b27381743f7 Mon Sep 17 00:00:00 2001 From: Daniel Bretoi Date: Sun, 15 Sep 2024 11:43:38 +0700 Subject: [PATCH 2/4] make image preview more generic --- plugins/preview-tui | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/plugins/preview-tui b/plugins/preview-tui index 200d3e33f..56f334164 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -21,7 +21,7 @@ # - man # - optional: bsdtar or atool for additional archive preview # - optional: bat for code syntax highlighting -# - optional: ueberzug, kitty terminal, wezterm terminal, img2sixel, viu, catimg or chafa for images +# - optional: ueberzug, kitty terminal, wezterm terminal, img2sixel, viu, catimg, timg or chafa for images # - optional: convert(ImageMagick) for playing gif preview (mandatory for kitty image previews) # - optional: mpv for gif and video # Also requires a terminal supporting the sixel (https://www.arewesixelyet.com/) @@ -131,7 +131,7 @@ ENVVARS+=( ) trap '' PIPE -exists() { type "$1" >/dev/null 2>&1 ;} +exists() { type "${1%% *}" >/dev/null 2>&1 ;} pkill() { command pkill "$@" >/dev/null 2>&1 ;} prompt() { clear; printf "%b" "$@"; cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" ;} pidkill() { @@ -450,16 +450,6 @@ image_preview() { kitty +kitten icat --silent --scale-up --place "$(($1 - 1))x$(($2 - 1))"@0x0 --transfer-mode=memory --stdin=no "$3" & elif [ "$NNN_TERMINAL" = "wezterm" ] && [[ "$NNN_PREVIEWIMGPROG" == +(|imgcat) ]]; then wezterm imgcat "$3" & - elif exists ueberzug && [[ "$NNN_PREVIEWIMGPROG" == +(|ueberzug) ]]; then - ueberzug_layer "$1" "$2" "$3" && return - elif exists catimg && [[ "$NNN_PREVIEWIMGPROG" == +(|catimg) ]]; then - catimg "$3" & - elif exists viu && [[ "$NNN_PREVIEWIMGPROG" == +(|viu) ]]; then - viu -t "$3" & - elif exists chafa && [[ "$NNN_PREVIEWIMGPROG" == +(|chafa) ]]; then - chafa "$3" & - elif exists img2sixel && [[ "$NNN_PREVIEWIMGPROG" == +(|img2sixel) ]]; then - img2sixel -g "$3" & elif exists "$NNN_PREVIEWIMGPROG"; then "$NNN_PREVIEWIMGPROG" "$3" & else From 7571d172aa46cfe9820f99f7e8686fe30aaeead9 Mon Sep 17 00:00:00 2001 From: Daniel Bretoi Date: Sun, 15 Sep 2024 11:45:29 +0700 Subject: [PATCH 3/4] add uberzug back --- plugins/preview-tui | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/preview-tui b/plugins/preview-tui index 56f334164..80597f348 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -450,6 +450,8 @@ image_preview() { kitty +kitten icat --silent --scale-up --place "$(($1 - 1))x$(($2 - 1))"@0x0 --transfer-mode=memory --stdin=no "$3" & elif [ "$NNN_TERMINAL" = "wezterm" ] && [[ "$NNN_PREVIEWIMGPROG" == +(|imgcat) ]]; then wezterm imgcat "$3" & + elif exists ueberzug && [[ "$NNN_PREVIEWIMGPROG" == +(|ueberzug) ]]; then + ueberzug_layer "$1" "$2" "$3" && return elif exists "$NNN_PREVIEWIMGPROG"; then "$NNN_PREVIEWIMGPROG" "$3" & else From aa04d6370bcd2745252bf82b9e7cbdef2c98a1d5 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sun, 15 Sep 2024 16:04:37 +0200 Subject: [PATCH 4/4] change and document variable expansion --- plugins/preview-tui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/preview-tui b/plugins/preview-tui index 80597f348..45177fdbb 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -112,7 +112,7 @@ ENVVARS=( "NNN_PREVIEWWIDTH=${NNN_PREVIEWWIDTH:-1920}" # width of generated preview images "NNN_PREVIEWHEIGHT=${NNN_PREVIEWHEIGHT:-1080}" # height of generated preview images "NNN_PREVIEWDIR=${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}" # location of generated preview images - "NNN_PREVIEWIMGPROG=${NNN_PREVIEWIMGPROG:-}" # program used to preview images + "NNN_PREVIEWIMGPROG=${NNN_PREVIEWIMGPROG:-}" # command used to preview images "NNN_PREVIEWVIDEO=${NNN_PREVIEWVIDEO:-}" # mpv backend used to preview video ) # Non-configurable environment variables @@ -131,7 +131,7 @@ ENVVARS+=( ) trap '' PIPE -exists() { type "${1%% *}" >/dev/null 2>&1 ;} +exists() { type "$1" >/dev/null 2>&1 ;} pkill() { command pkill "$@" >/dev/null 2>&1 ;} prompt() { clear; printf "%b" "$@"; cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" ;} pidkill() { @@ -452,7 +452,7 @@ image_preview() { wezterm imgcat "$3" & elif exists ueberzug && [[ "$NNN_PREVIEWIMGPROG" == +(|ueberzug) ]]; then ueberzug_layer "$1" "$2" "$3" && return - elif exists "$NNN_PREVIEWIMGPROG"; then + elif exists "${NNN_PREVIEWIMGPROG%% *}"; then # can include command flags; only check first word "$NNN_PREVIEWIMGPROG" "$3" & else fifo_pager print_bin_info "$3" && return