commit 7c67234d6837ef9f9e784efbe5a59fd2d636a730
parent 841129c0ec18b21ce389c6d8f2ea9de18a5725ea
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Fri, 9 Oct 2020 15:36:43 +0200
lf & shell: extracted opener script, more previews
Former-commit-id: f73b026c9bdcceb87022b80d1682e4ac67cf123e
Diffstat:
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/lf/lfrc b/lf/lfrc
@@ -30,15 +30,7 @@ set preview true
# }}}
# Command definitions {{{
# define a custom 'open' command
-cmd open &{{
- case $(file --mime-type "$f" -bL) in
- text/*|application/json) $EDITOR $fx;;
- image/*) sxiv $fx 2>&1 & disown;;
- application/epub*) ebook-viewer $fx >/dev/null 2>&1 & disown;;
- video/*) mpvq $f;;
- *) for f in $fx; do open "$f" > /dev/null 2> /dev/null & disown; done;;
- esac
-}}
+cmd open $opener $fx
# define a custom 'rename' command without prompt for overwrite
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
@@ -149,7 +141,7 @@ map X !$f
# dedicated keys for file opener actions
map o
map O
-map o :open $fx
+map o open $fx
map O push hol
map v ql_preview
map r reload
@@ -170,7 +162,7 @@ map R push :rename<space>
map cw push :rename<space>
map E $$EDITOR $f
map D delete
-map <enter> :open $fx
+map <enter> open $fx
map S shell
map Y copy_path
diff --git a/lf/preview b/lf/preview
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-case "$1" in
+case "$(printf "%s" "$1" | tr '[:upper:]' '[:lower:]')" in
*.tgz|*.tar.gz) tar tzf "$1";;
*.tar.bz2|*.tbz2) tar tjf "$1";;
*.tar.txz|*.txz) xz --list "$1";;
@@ -11,26 +11,21 @@ case "$1" in
*.o) nm "$1" | less ;;
# *.torrent) transmission-show "$1";;
# *.iso) iso-info --no-header -l "$1";;
- # *odt,*.ods,*.odp,*.sxw) odt2txt "$1";;
- # *.doc) catdoc "$1" ;;
- # *.docx) docx2txt "$1" - ;;
- *.csv) cat "$1" | sed s/,/\\n/g ;;
+ *.epub|*.rtf|*.doc|*.docx|*.otd|*.ods|*.odp|*.sxw)
+ pandoc -s -t markdown -- "$1" | bat --color=always --theme=base16
+ exit 1
+ ;;
+ *.csv) sed s/,/\\n/g "$1";;
*.pdf)
CACHE=$(mktemp)
pdftoppm -png -f 1 -singlefile "$1" "$CACHE"
imgpreview "$CACHE.png"
rm "$CACHE"
;;
- # *.epub)
- # CACHE=$(mktemp)
- # epub-thumbnailer "$1" "$CACHE" 1024
- # imgpreview "$CACHE"
- # rm "$CACHE"
- # ;;
- *.bmp|*.jpg|*.jpeg|*.png|*.xpm)
+ *.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.gif)
imgpreview "$1"
;;
- *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.flac)
+ *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx])
exiftool "$1"
;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx)
diff --git a/scripts/opener b/scripts/opener
@@ -0,0 +1,10 @@
+#!/bin/sh
+[ $# -gt 0 ] || { printf "File required in argument.\n" && exit 1; }
+case $(file --mime-type "$1" -bL) in
+ text/*|application/json|inode/x-empty) $EDITOR "$1";;
+ image/*) setsid -f sxiv "$@" 2>&1;;
+ application/epub*) setsid -f ebook-viewer "$1" >/dev/null 2>&1;;
+ video/*) mpvq "$@";;
+ audio/*) mpv --no-audio-display --no-video --volume=50 "$1";;
+ *) setsid -f open "$1" > /dev/null 2>&1;;
+esac