nnn
with preview-tui
plugin on the F(x)tec Pro¹ running SailfishOS
Asciinema (installed on SailfishOS using pip
) degraded the image previews, they looked a bit better on the phone.
Instructions for SailfishOS
The preview-tui
plugin for nnn
requires tmux 3.2
(Openrepos.net). For this cast, I used:
-
viu
for image preview (Openrepos), -
tree-node-cli
for directory preview (installed with theNode.js
package on Openrepos usingnpm -g install tree-node-cli
, and added to$PATH
).
To enable true colors inside tmux
, add export COLORTERM='24bit'
to your ~/.bashrc
. Then add the following options to ~/.tmux.conf
and make sure you use a terminal compatible with true colors (Havoc, Literm):
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color*:Tc"
This is the modification of plugin-tui
I used to enable viu
and tree-cli
:
#!/usr/bin/env sh
# Description: Text based file previewer
#
# Note: This plugin needs a "NNN_FIFO" to work.
#
# Dependencies: tmux (>=3.0) or xterm or $TERMINAL, less or $PAGER,
# file, stat, tree, man, tar, unzip, ...
# ... add you own! (see examples in code)
#
# Usage:
# You need to set a NNN_FIFO path and set a key for the plugin,
# then start `nnn`:
#
# $ nnn -a
#
# or
#
# $ NNN_FIFO=/tmp/nnn.fifo nnn
#
# Then in `nnn`, launch the `preview-tui` plugin.
#
# If you provide the same NNN_FIFO to all nnn instances, there will be a
# single common preview window. I you provide different FIFO path (e.g.
# with -a), they will be independent.
#
# Configure SPLIT to either "h" or "v" to set a 'h'orizontal split or a
# 'v'ertical split
#
# Shell: POSIX compliant
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste
TERMINAL="${TERMINAL:-xterm}"
PAGER="${PAGER:-less -R}"
fifo_pager() {
cmd="$1"
shift
# We use a FIFO to access $PAGER PID in jobs control
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return
$PAGER < "$tmpfifopath" &
(
exec > "$tmpfifopath"
"$cmd" "$@" &
)
rm "$tmpfifopath"
}
preview_file () {
kill %- %+ 2>/dev/null && wait %- %+ 2>/dev/null
clear
encoding="$(file -Lb --mime-encoding -- "$1")"
# Detect mime type
mimetype="$(file -Lb --mime-type -- "$1")"
# Detect file extention
ext="${1##*.}"
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
if [ -d "$1" ]; then
# Print directory tree
cd "$1" || return
fifo_pager tree -F -L 3
elif [ "${mimetype%%/*}" = "image" ] ; then
viu "$1" &
#elif [ "$mimetype" = "text/troff" ] ; then
# fifo_pager man -Pcat -l "$1"
elif [ "$mimetype" = "application/zip" ] ; then
fifo_pager unzip -l "$1"
elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ] ; then
fifo_pager tar -tvf "$1"
elif [ "$encoding" = "binary" ] ; then
# Binary file: just print filetype info
echo "-------- binary file --------"
file -b "$1"
echo
stat "$1"
else
# Text file:
$PAGER "$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
preview_file "$1"
exec < "$NNN_FIFO"
while read -r selection ; do
preview_file "$selection"
done
exit 0
fi
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.' ; then
if [ -z "$SPLIT" ] && [ $(($(tput lines) * 2)) -gt "$(tput cols)" ] ; then
SPLIT='v'
elif [ "$SPLIT" != 'v' ] ; then
SPLIT='h'
fi
tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -d"$SPLIT" "$0" "$1"
else
PREVIEW_MODE=1 $TERMINAL -e "$0" "$1" &
fi
More by kabouik
Share this recording
Link
Append ?t=30
to start the playback at 30s, ?t=3:20
to start the playback at 3m 20s.
Embed image link
Use snippets below to display a screenshot linking to this recording.
Useful in places where scripts are not allowed (e.g. in a project's README file).
HTML:
Markdown:
Embed the player
If you're embedding on your own page or on a site which permits script tags, you can use the full player widget:
Paste the above script tag where you want the player to be displayed on your page.
See embedding docs for additional options.
Download this recording
You can download this recording in asciicast v2 format, as a .cast file.
DownloadReplay in terminal
You can replay the downloaded recording in your terminal using the
asciinema play
command:
asciinema play 336443.cast
If you don't have asciinema CLI installed then see installation instructions.
Use with stand-alone player on your website
Download asciinema player from
the releases page
(you only need .js
and .css
file), then use it like this:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="asciinema-player.css" />
</head>
<body>
<div id="player"></div>
<script src="asciinema-player.min.js"></script>
<script>
AsciinemaPlayer.create(
'/assets/336443.cast',
document.getElementById('player'),
{ cols: 135, rows: 36 }
);
</script>
</body>
</html>
See asciinema player quick-start guide for full usage instructions.
Generate GIF from this recording
While this site doesn't provide GIF conversion at the moment, you can still do it yourself with the help of asciinema GIF generator utility - agg.
Once you have it installed, generate a GIF with the following command:
agg https://asciinema.org/a/336443 demo.gif
Or, if you already downloaded the recording file:
agg demo.cast demo.gif
Check agg --help
for all available options. You can change font
family and size, select color theme, adjust speed and more.
See agg manual for full usage instructions.