Skip to content
iambumblehead edited this page Mar 28, 2024 · 19 revisions

thu.sh

pending details showing how to use thu.sh

terminal emulators

iTerm2, kitty and foot can render images with this script. Sixel support for other terminals is listed here https://www.arewesixelyet.com/.

term xterm

Values below should be added to your ~/.Xresources file before the session is started or restarted,

~/.Xresources

xterm*maxStringParse: 10000000
xterm*maxGraphicSize: 10000x10000
xterm*decTerminalID: vt340
xterm*numColorRegisters: 256

term foot

Many versions of foot terminal emulator have a bug described here. When desktop or window scaling are used, foot will render images in a smaller size. As a work-around use -z $SCALE to apply a zoom factor to image sizes.

filemanagers

Using thu.sh with ncurses file managers likely requires two things,

  1. The filemanager must call thu.sh -j before ncurses is started. This reason for this is that ncurses takes control of stderr and stdout devices and prevents thu.sh from using them to detect things like terminal size, cell size and sixel support. thu.sh -j will query details from the terminal, to store and reuse them when rendering images. To learn more about this, see the discussion here.

  2. The filemanager must call thu.sh with the target filepath and view area size. eg, thu.sh -ck $PATH $WIDTH $HEIGHT

filemanager, vifm

vifm

Download and extract thu.sh to vifm's xdg ~/.config/vifm/scripts/ using one-liner below,

curl -sl \
  https://api.github.com/repos/iambumblehead/thu.sh/releases/latest \
  | grep "tarball_url" \
  | cut -d\" -f4 \
  | xargs curl -L -o thu.tar.gz \
  && tar -xf thu.tar.gz \
  && mv iambumblehead-thu.sh* thu \
  && cp thu/thu.sh ~/.config/vifm/scripts/ \
  && sleep 2; chmod +x ~/.config/vifm/scripts/thu.sh \
  && rm -rf thu thu.tar.gz

Update vifmrc to use thu.sh by including the let and fileviewer expressions below. Only this fileviewer should include the extensions it contains --remove other fileviewer expressions or matching extensions anywhere else in the vifmrc file,

~/.config/vifm/vifmrc

" generates state session string with esc queried values,
" for example, cell pixel width and height and maximum supported image size
let $SESS = system('thu.sh -j')

" thu.sh is called with -ck
" '-c' tells thu.sh to process %pw and %ph as cell units
" '-k' tells thu.sh to use the state state session string from the '-j' call above
" '-z 3' include this with foot terminal emulator on scaled desktop
fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.svg,*.pdf,*.epub,
           \*.ttf,*.otf,*.woff,*.wav,*.mp3,*.flac,*.m4a,*.wma,*.ape,
           \*.ac3,*.og[agx],*.spx,*.opus,*.aac,*.mpga,*.avi,*.mp4,
           \*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,
           \*.fl[icv],*.m2v,*.mov,*.webm,*.ts,*.mts,*.m4v,*.r[am],
           \*.qt,*.divx,*.as[fx],*.unknown_video},
        \ thu.sh -ck %c %px %py %pw %ph %pd

filemanager, vifm+kitty

kitty needs a special vifm configuration that includes the "%N" macro option. Use this in your vifmrc file,

~/.config/vifm/vifmrc

" generates state session string with esc queried values,
" for example, cell pixel width and height and maximum supported image size
let $SESS = system('thu.sh -j')

" thu.sh is called with -ck
" '-c' tells thu.sh to process %pw and %ph as cell units
" '-k' tells thu.sh to use the state state session string from the '-j' call above
fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.svg,*.pdf,*.epub,
           \*.ttf,*.otf,*.woff,*.wav,*.mp3,*.flac,*.m4a,*.wma,*.ape,
           \*.ac3,*.og[agx],*.spx,*.opus,*.aac,*.mpga,*.avi,*.mp4,
           \*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,
           \*.fl[icv],*.m2v,*.mov,*.webm,*.ts,*.mts,*.m4v,*.r[am],
           \*.qt,*.divx,*.as[fx],*.unknown_video},
        \ thu.sh -ck %c %px %py %pw %ph %pd %N
        \ %pc
        \ thu.sh -w %N

related,

Clone this wiki locally