cleanup preview, add toggle bind
This commit is contained in:
parent
ad7a638efb
commit
e1b630c543
3 changed files with 73 additions and 46 deletions
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# kitty +kitten icat --clear --silent --stdin no --transfer-mode memory >/dev/tty
|
|
||||||
if [ -n "$FIFO_UEBERZUG" ]; then
|
if [ -n "$FIFO_UEBERZUG" ]; then
|
||||||
printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
|
printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -12,6 +12,16 @@ set cleaner ~/.config/lf/clean
|
||||||
set cursorpreviewfmt "\033[7;90m"
|
set cursorpreviewfmt "\033[7;90m"
|
||||||
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033[32m » \033[33m%f\033[0m"
|
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033[32m » \033[33m%f\033[0m"
|
||||||
|
|
||||||
|
cmd toggle-preview %{{
|
||||||
|
if [ "$(basename $lf_previewer)" = "preview" ]; then
|
||||||
|
lf -remote "send $id set previewer mediainfo"
|
||||||
|
else
|
||||||
|
lf -remote "send $id set previewer ~/.config/lf/preview"
|
||||||
|
fi
|
||||||
|
$lf_cleaner
|
||||||
|
lf -remote "send $id reload"
|
||||||
|
}}
|
||||||
|
|
||||||
cmd open $set -f; rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p 0 $fx; clear
|
cmd open $set -f; rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p 0 $fx; clear
|
||||||
|
|
||||||
cmd open-with ${{
|
cmd open-with ${{
|
||||||
|
@ -137,19 +147,17 @@ cmd fzfgrep ${{
|
||||||
# workon -n $(workon | fzf)
|
# workon -n $(workon | fzf)
|
||||||
# }}
|
# }}
|
||||||
|
|
||||||
|
|
||||||
# Bindings
|
# Bindings
|
||||||
map <c-c>a fzfsearch
|
map <c-c>a fzfsearch
|
||||||
map <c-c>t fzftags
|
map <c-c>t fzftags
|
||||||
map <c-c>m fzfmarks
|
map <c-c>m fzfmarks
|
||||||
map <c-c>f fzfshortcut
|
map <c-c>f fzfshortcut
|
||||||
map <c-c>g fzfgrep
|
map <c-c>g fzfgrep
|
||||||
# map w fzfworkon
|
|
||||||
map D trash
|
map D trash
|
||||||
map <c-d> $trash-restore $PWD
|
map <c-d> $trash-restore $PWD
|
||||||
map T &rm -rf -- $fx
|
map T &rm -rf -- $fx
|
||||||
map <c-e> $aunpack $fx
|
map <c-e> $aunpack $fx
|
||||||
map R rsyncto
|
map R toggle-preview
|
||||||
map P link
|
map P link
|
||||||
# map S share
|
# map S share
|
||||||
map <c-g> lazygit
|
map <c-g> lazygit
|
||||||
|
|
|
@ -1,66 +1,86 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
RED="\033[31m"
|
||||||
|
RESET="\033[0m"
|
||||||
|
|
||||||
set -C -f
|
set -C -f
|
||||||
|
|
||||||
|
|
||||||
image() {
|
image() {
|
||||||
f=$1
|
f=$1
|
||||||
w=$2
|
w=$2
|
||||||
h=$3
|
h=$3
|
||||||
x=$4
|
x=$4
|
||||||
y=$5
|
y=$5
|
||||||
# kitty +kitten icat --clear --stdin no --silent --transfer-mode memory --place "${w}x${h}@${x}x${y}" "$f" >/dev/tty
|
if [ -f "$1" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1; then
|
||||||
if [ -f "$1" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1; then
|
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$(($4 + 3))" "$(($5 + 1))" "$(($2 - 6))" "$(($3 - 2))" "$1" >"$FIFO_UEBERZUG"
|
||||||
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$(($4 + 3))" "$(($5 + 1))" "$(($2-6))" "$(($3-2))" "$1" > "$FIFO_UEBERZUG"
|
fi
|
||||||
fi
|
exit 1
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
video() {
|
video() {
|
||||||
f=$1
|
f=$1
|
||||||
w=$2
|
w=$2
|
||||||
h=$3
|
h=$3
|
||||||
x=$4
|
x=$4
|
||||||
y=$5
|
y=$5
|
||||||
thumb="$(vidthumb "$f")" || ( printf "%b" "\033[31mvidthumb script not in path\033[0m"; return 1 )
|
thumb="$(vidthumb "$f")" || (
|
||||||
image "$thumb" "$w" "$h" "$x" "$y"
|
printf "%b" "\033[31mvidthumb script not in path\033[0m"
|
||||||
return 1
|
return 1
|
||||||
|
)
|
||||||
|
image "$thumb" "$w" "$h" "$x" "$y"
|
||||||
}
|
}
|
||||||
|
|
||||||
batorcat() {
|
batorcat() {
|
||||||
f=$1
|
f=$1
|
||||||
w=$2
|
w=$2
|
||||||
command -v bat > /dev/null 2>&1 && bat --color=always --style=plain --pager=never --terminal-width "$((w-2))" "$f" && exit 0
|
command -v bat >/dev/null 2>&1 && bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 0
|
||||||
command -v batcat > /dev/null 2>&1 && batcat --color=always --style=plain --pager=never --terminal-width "$((w-2))" "$f" && exit 0
|
command -v batcat >/dev/null 2>&1 && batcat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 0
|
||||||
cat "$f" && exit 0
|
cat "$f" && exit 0
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
if ! command -v $1 >/dev/null 2>&1; then
|
||||||
|
printf "%b" "${RED}Cannot execute $1${RESET}"
|
||||||
|
exit 1
|
||||||
|
elif $@; then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
printf "%b" "${RED}Failed to run command: $*${RESET}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
|
CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
|
||||||
|
|
||||||
case "$(xdg-mime query filetype "$1")" in
|
case "$(xdg-mime query filetype "$1")" in
|
||||||
*/x-bzip-compressed-tar|*/x-compressed-tar|*/x-xz-compressed-tar) als -- "$1" && exit 0 || printf "%b" "\033[31matool failed\033[0m" && exit 1;;
|
*/x-bzip-compressed-tar | */x-compressed-tar | */x-xz-compressed-tar) run als -- "$1" ;;
|
||||||
*/x-7z-compressed|*/vnd.rar|*/x-tar|*/zip|*/x-java-archive|*/x-xz) 7z l "$1" | sed 1,11d && exit 0 || printf "%b" "\033[31m7zip failed\033[0m" && exit 1;;
|
*/x-7z-compressed | */vnd.rar | */x-tar | */zip | */x-java-archive | */x-xz) run 7z l "$1" | sed 1,11d ;;
|
||||||
*/x-cd-image) iso-info --no-header -l "$1" && exit 0 || printf "%b" "\033[31mlibcdio failed\033[0m" && exit 1;;
|
*/x-cd-image) run iso-info --no-header -l "$1" ;;
|
||||||
*/x-bittorrent) transmission-show "$1" && exit 0 || printf "%b" "\033[31mtransmission-cli failed\033[0m" && exit 1;;
|
*/x-bittorrent) run transmission-show "$1" ;;
|
||||||
*/vnd.sun.xml.writer) odt2txt "$1" && exit 0 || printf "%b" "\033[31modt2txt failed\033[0m" && exit 1;;
|
*/vnd.sun.xml.writer) run odt2txt "$1" ;;
|
||||||
*/msword) catdoc "$1" && exit 0 || printf "%b" "\033[31mcatdoc failed\033[0m" && exit 1;;
|
*/msword) run catdoc "$1" ;;
|
||||||
*/vnd.openxmlformats-officedocument.wordprocessingml.document) docx2txt < "$1" && exit 0 || printf "%b" "\033[31mdocx2txt failed\033[0m" && exit 1;;
|
*/vnd.openxmlformats-officedocument.wordprocessingml.document) run docx2txt <"$1" ;;
|
||||||
*/vnd.ms-excel) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv && exit 0 || printf "%b" "\033[31mgnumeric failed\033[0m" && exit 1;;
|
*/vnd.ms-excel) run ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
||||||
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv && exit 0 || printf "%b" "\033[31mgnumeric failed\033[0m" && exit 1;;
|
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) run ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
||||||
*/epub+zip) [ ! -f "$CACHE" ] && epub-thumbnailer "$1" "$CACHE" 1024; image "$CACHE" "$2" "$3" "$4" "$5" && exit 0 || printf "%b" "\033[31mepubthumbnailer failed (https://github.com/marianosimone/epub-thumbnailer)\033[0m" && exit 1;;
|
*/epub+zip) [ ! -f "$CACHE" ] && run epub-thumbnailer "$1" "$CACHE" 1024 && image "$CACHE" "$2" "$3" "$4" "$5" ;;
|
||||||
*/pgp-encrypted) gpg -d -- "$1" && exit 0 || printf "%b" "\033[31mgpg failed\033[0m" && exit 1;;
|
*/pgp-encrypted) run gpg -d -- "$1" ;;
|
||||||
*/pkix-cert) openssl x509 -text -noout -in "$1" && exit 0 || printf "%b" "\033[31mopenssl failed\033[0m" && exit 1;;
|
*/pkix-cert) run openssl x509 -text -noout -in "$1" ;;
|
||||||
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
image/svg+xml) [ ! -f "$CACHE" ] && run inkscape --convert-dpi-method=none -o "$CACHE" --export-overwrite -D --export-png-color-mode=RGBA_16 "$1" && image $CACHE "$2" "$3" "$4" "$5" ;;
|
||||||
video/*) video "$1" "$2" "$3" "$4" "$5" ;;
|
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
||||||
*opendocument*) odt2txt "$1" && exit 0 || printf "%b" "\033[31modt2txt failed\033[0m" && exit 1;;
|
video/*) video "$1" "$2" "$3" "$4" "$5" ;;
|
||||||
*/markdown) lowdown -Tterm "$1" && exit 0 || printf "%b" "\033[31mlowdown failed \033[0m" && exit 1;;
|
*opendocument*) run odt2txt "$1" ;;
|
||||||
*/html) lynx -dump "$1" && exit 0 || w3m -dump "$1" && exit 0 || printf "%b" "\033[31neither lynx nor w3m installed\033[0m" && exit 1;;
|
*/markdown) run lowdown -Tterm "$1" ;;
|
||||||
text/*|*/json|*/xml) batorcat "$1" "$2" ;;
|
*/html) run lynx -dump "$1" ;;
|
||||||
*/pdf) [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"; image "${CACHE}.jpg" "$2" "$3" "$4" "$5" && exit 0 || printf "%b" "\033[31mpoppler-utils/poppler failed\033[0m" && exit 1;;
|
text/* | */json | */xml) batorcat "$1" "$2" ;;
|
||||||
|
*/pdf) [ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE" && image "${CACHE}.jpg" "$2" "$3" "$4" "$5" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$(file -bL --mime-type "$1")" in
|
case "$(file -bL --mime-type "$1")" in
|
||||||
text/*) batorcat "$1" "$2" ;;
|
text/*) batorcat "$1" "$2" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
xdg-mime query filetype "$1"
|
xdg-mime query filetype "$1"
|
||||||
mediainfo "$1"
|
mediainfo "$1"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue