dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a6cf701f44dfff9d5e3c9ed2a57f714b99f95d9c
parent d9550b50f066bd9ffe629868bf5be2a2b5dc7492
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Tue,  2 Apr 2019 20:43:29 +0200

Add icons and previews for images and video to vifm

Diffstat:
M.commands.sh | 2+-
A.config/vifm/scripts/README | 7+++++++
A.config/vifm/scripts/imgc | 16++++++++++++++++
A.config/vifm/scripts/imgt | 38++++++++++++++++++++++++++++++++++++++
A.config/vifm/scripts/vifmimg | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
M.config/vifm/vifmrc | 42+++++++++++++++++++++++++++++++++++-------
Abin/vifmrun | 15+++++++++++++++
7 files changed, 165 insertions(+), 8 deletions(-)

diff --git a/.commands.sh b/.commands.sh @@ -6,7 +6,7 @@ alias b='bash' alias z='zsh' alias v='vim' -alias n='vifm' +alias n='vifmrun' ## cd alias cg='c "$(git rev-parse --show-toplevel)"' # cd under git repo diff --git a/.config/vifm/scripts/README b/.config/vifm/scripts/README @@ -0,0 +1,6 @@ +This directory is dedicated for user-supplied scripts/executables. +vifm modifies its PATH environment variable to let user run those +scripts without specifying full path. All subdirectories are added +as well. File in a subdirectory overrules file with the same name +in parent directories. Restart might be needed to recognize files +in newly created or renamed subdirectories.+ \ No newline at end of file diff --git a/.config/vifm/scripts/imgc b/.config/vifm/scripts/imgc @@ -0,0 +1,16 @@ +#!/bin/bash + +W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" +FONTH=18 # Size of one terminal row +FONTW=9 # Size of one terminal column + +X=$1 +Y=$2 +COLUMNS=$3 +LINES=$4 + +x=$((FONTW * X)) +y=$((FONTH * Y)) + +erase="6;$x;$y;$(( FONTW*COLUMNS ));$(( FONTH*LINES ))\n3;" +echo -e "$erase" | $W3MIMGDISPLAY diff --git a/.config/vifm/scripts/imgt b/.config/vifm/scripts/imgt @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Based on script by z3bra -- 2014-01-21 + +W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" +FONTH=16 # Size of one terminal row +FONTW=9 # Size of one terminal column + +X=$1 +Y=$2 +COLUMNS=$3 +LINES=$4 +FILENAME=$5 + +read width height <<< `echo "5;$FILENAME" | $W3MIMGDISPLAY` +if [ -z "$width" -o -z "$height" ]; then + echo 'Error: Failed to obtain image size.' + exit 1 +fi + +x=$((FONTW * X)) +y=$((FONTH * Y)) + +max_width=$((FONTW * COLUMNS)) +max_height=$((FONTH * LINES)) + +if [ "$width" -gt "$max_width" ]; then + height=$((height * max_width / width)) + width=$max_width +fi +if [ "$height" -gt "$max_height" ]; then + width=$((width * max_height / height)) + height=$max_height +fi + +w3m_command="0;1;$x;$y;$width;$height;;;;;$FILENAME\n4;\n3;" + +echo -e "$w3m_command" | $W3MIMGDISPLAY diff --git a/.config/vifm/scripts/vifmimg b/.config/vifm/scripts/vifmimg @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +readonly ID_PREVIEW="preview" + +#AUTO_REMOVE="yes" +# By enabling this option the script will remove the preview file after it is drawn +# and by doing so the preview will always be up-to-date with the file. +# This however, requires more CPU and therefore affects the overall performance. + +if [ -e "$FIFO_UEBERZUG" ]; then + if [[ "$1" == "draw" ]]; then + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ + [path]="${PWD}/$6") \ + > "$FIFO_UEBERZUG" + + elif [[ "$1" == "videopreview" ]]; then + echo -e "Loading preview..\nFile: $6" + [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" + [[ ! -f "/tmp${PWD}/$6.png" ]] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp${PWD}/$6.png" -s 0 -q 10 + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ + [path]="/tmp${PWD}/$6.png") \ + > "$FIFO_UEBERZUG" + + elif [[ "$1" == "gifpreview" ]]; then + echo -e "Loading preview..\nFile: $6" + [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" && convert -coalesce "${PWD}/$6" "/tmp${PWD}/$6/$6.png" + for frame in $(ls -1 /tmp${PWD}/$6/$6*.png | sort -V); do + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ + [path]="$frame") \ + > "$FIFO_UEBERZUG" + # Sleep between frames to make the animation smooth. + sleep .07 + done + + elif [[ "$1" == "pdfpreview" ]]; then + echo -e "Loading preview..\nFile: $6" + [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" + [[ ! -f "/tmp${PWD}/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp${PWD}/$6" + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" + [x]="$2" [y]="$3" [width]="$4" [height]="$5" \ + [path]="/tmp${PWD}/$6.png") \ + > "$FIFO_UEBERZUG" + + elif [[ "$1" == "clear" ]]; then + declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \ + > "$FIFO_UEBERZUG" + [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp${PWD}/$6.png" ]] && rm -f "/tmp${PWD}/$6.png" + [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp${PWD}/$6/" ]] && rm -rf "/tmp${PWD}/$6/" + + fi +fi diff --git a/.config/vifm/vifmrc b/.config/vifm/vifmrc @@ -181,6 +181,9 @@ fileviewer *.pdf pdftotext -nopgbrk %c - " PostScript filextype *.ps,*.eps,*.ps.gz + \ vifmimg pdfpreview %px %py %pw %ph %c + \ %pc + \ vifmimg clear \ {View in zathura} \ zathura %f, \ {View in gv} @@ -217,7 +220,10 @@ filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob, fileviewer *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob, \*.fl[icv],*.m2v,*.mov,*.webm,*.ts,*.mts,*.m4v,*.r[am],*.qt,*.divx, \*.as[fx] - \ ffprobe -pretty %c 2>&1 + \ vifmimg videopreview %px %py %pw %ph %c + \ %pc + \ vifmimg clear + " \ ffprobe -pretty %c 2>&1 " Web filextype *.html,*.htm @@ -244,8 +250,16 @@ filextype *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm \ gpicview %c, \ {View in shotwell} \ shotwell, -fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm - \ convert -identify %f -verbose /dev/null +"fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm +fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.xpm + \ vifmimg draw %px %py %pw %ph %c + \ %pc + \ vifmimg clear + "\ convert -identify %f -verbose /dev/null +fileviewer *.gif + \ vifmimg gifpreview %px %py %pw %ph %c + \ %pc + \ vifmimg clear " OpenRaster filextype *.ora @@ -379,6 +393,24 @@ filextype */ " For Windows: " filetype * start, explorer +" GETTING ICONS TO DISPLAY IN VIFM +" You need the next 14 lines! + +" file types +set classify=' :dir:/, :exe:, :reg:, :link:' +" various file names +set classify+=' ::../::, ::*.sh::, ::*.[hc]pp::, ::*.[hc]::, ::/^copying|license$/::, ::.git/,,*.git/::, ::*.epub,,*.fb2,,*.djvu::, ::*.pdf::, ::*.htm,,*.html,,**.[sx]html,,*.xml::' +" archives +set classify+=' ::*.7z,,*.ace,,*.arj,,*.bz2,,*.cpio,,*.deb,,*.dz,,*.gz,,*.jar,,*.lzh,,*.lzma,,*.rar,,*.rpm,,*.rz,,*.tar,,*.taz,,*.tb2,,*.tbz,,*.tbz2,,*.tgz,,*.tlz,,*.trz,,*.txz,,*.tz,,*.tz2,,*.xz,,*.z,,*.zip,,*.zoo::' +" images +set classify+=' ::*.bmp,,*.gif,,*.jpeg,,*.jpg,,*.ico,,*.png,,*.ppm,,*.svg,,*.svgz,,*.tga,,*.tif,,*.tiff,,*.xbm,,*.xcf,,*.xpm,,*.xspf,,*.xwd::' +" audio +set classify+=' ::*.aac,,*.anx,,*.asf,,*.au,,*.axa,,*.flac,,*.m2a,,*.m4a,,*.mid,,*.midi,,*.mp3,,*.mpc,,*.oga,,*.ogg,,*.ogx,,*.ra,,*.ram,,*.rm,,*.spx,,*.wav,,*.wma,,*.ac3::' +" media +set classify+=' ::*.avi,,*.ts,,*.axv,,*.divx,,*.m2v,,*.m4p,,*.m4v,,.mka,,*.mkv,,*.mov,,*.mp4,,*.flv,,*.mp4v,,*.mpeg,,*.mpg,,*.nuv,,*.ogv,,*.pbm,,*.pgm,,*.qt,,*.vob,,*.wmv,,*.xvid::' +" office files +set classify+=' ::*.doc,,*.docx::, ::*.xls,,*.xls[mx]::, ::*.pptx,,*.ppt::' + " ------------------------------------------------------------------------------ " What should be saved automatically between vifm runs @@ -452,10 +484,6 @@ nnoremap <f6> :move<cr> nnoremap <f7> :mkdir<space> nnoremap <f8> :delete<cr> - -nnoremap I cw<c-a> -nnoremap cc cw<c-u> -nnoremap A cw map q ZQ map x :!sxiv -ft * 2>/dev/null &<CR> nnoremap o :file &<cr>l diff --git a/bin/vifmrun b/bin/vifmrun @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" + +function cleanup { + rm "$FIFO_UEBERZUG" 2>/dev/null + pkill -P $$ 2>/dev/null +} + +rm "$FIFO_UEBERZUG" 2>/dev/null +mkfifo "$FIFO_UEBERZUG" +trap cleanup EXIT +tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash & + +vifm +cleanup