cleanup, prepping for sixel support in lf
This commit is contained in:
parent
03c3857f72
commit
994453b5e2
|
@ -1,5 +1,5 @@
|
|||
# Basic vars
|
||||
set ratios 1:2:4
|
||||
set ratios 1:2:6
|
||||
set shellopts '-eu'
|
||||
set ifs "\n"
|
||||
set findlen 1
|
||||
|
|
|
@ -5,32 +5,21 @@ RESET="\033[0m"
|
|||
|
||||
set -C -f
|
||||
|
||||
f=$1
|
||||
w=$2
|
||||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
f=$1 w=$2 h=$3 x=$4 y=$5
|
||||
|
||||
image() {
|
||||
f=$1
|
||||
w=$2
|
||||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
# TODO: Maybe append some mediainfo output into the image with ffmpeg (when there's enough space)
|
||||
# I assume that will take a bit of math that I'll try to implement in perl or python
|
||||
if [ -f "$1" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1; then
|
||||
f=$1 w=$2 h=$3 x=$4 y=$5
|
||||
if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
||||
# chafa "$f" -f sixel -s "$(($2 - 2))x$3" --animate false
|
||||
if 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"
|
||||
fi
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
video() {
|
||||
f=$1
|
||||
w=$2
|
||||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
f=$1 w=$2 h=$3 x=$4 y=$5
|
||||
thumb="$(vidthumb "$f")" || (
|
||||
printf "%b" "\033[31mvidthumb script not in path\033[0m"
|
||||
return 1
|
||||
|
@ -39,10 +28,10 @@ video() {
|
|||
}
|
||||
|
||||
text() {
|
||||
f=$1
|
||||
w=$2
|
||||
f=$1 w=$2
|
||||
bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 1
|
||||
cat "$f"; exit 1
|
||||
cat "$f"
|
||||
exit 1
|
||||
}
|
||||
|
||||
run() {
|
||||
|
@ -60,7 +49,6 @@ run() {
|
|||
|
||||
mimetest() {
|
||||
case "$1" in
|
||||
text/*) text "$f" "$w" ;;
|
||||
*/pdf)
|
||||
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
|
||||
image "${CACHE}.jpg" "$w" "$h" "$x" "$y"
|
||||
|
@ -87,13 +75,13 @@ mimetest() {
|
|||
image/*) image "$f" "$w" "$h" "$x" "$y" ;;
|
||||
video/*) video "$f" "$w" "$h" "$x" "$y" ;;
|
||||
*opendocument*) run odt2txt "$f" ;;
|
||||
*/markdown) run lowdown -Tterm "$f" ;;
|
||||
*/markdown) run mdcat "$f" ;;
|
||||
*/html) run lynx -dump "$f" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
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="${XDG_CACHE_HOME}/lf/thumbnail-$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
|
||||
|
||||
filerun="$(file --brief --dereference --mime-type "$f")"
|
||||
mimetest "$filerun" && exit 1
|
||||
|
@ -103,13 +91,11 @@ if command -v gio 1>/dev/null 2>&1; then
|
|||
mimetest "$giorun" && exit 1
|
||||
fi
|
||||
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
|
||||
mediainfo "$1" | head -n-2 | grep -v -e "Complete name" -e "General"
|
||||
|
||||
case $(file -b "$f") in
|
||||
*ascii* | *utf*) text "$f" "$w";;
|
||||
*ASCII* | *UTF*) text "$f" "$w";;
|
||||
*)
|
||||
printf "%b" "\$(file --mime-type)\t\t\t : $filerun\n"
|
||||
[ -n "$giorun" ] && printf "%b" "\$(gio info)\t\t\t\t : $giorun\n"
|
||||
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 1
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# vim: set ft=sh
|
||||
[ ! -f $XDG_DATA_HOME/zsh/history ] && mkdir -p $XDG_DATA_HOME/zsh && touch $XDG_DATA_HOME/zsh/history
|
||||
|
||||
setopt HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS HIST_VERIFY BANG_HIST interactive_comments autocd noflowcontrol longlistjobs nonomatch notify hash_list_all share_history histignorespace PROMPT_SUBST
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# vim: set ft=sh
|
||||
HISTSIZE=10000000
|
||||
SAVEHIST=10000000
|
||||
HISTFILE="$XDG_DATA_HOME/zsh/history"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# vim: set ft=sh:
|
||||
#!/bin/zsh
|
||||
venv_prompt() {
|
||||
[[ -n ${VIRTUAL_ENV} ]] || return
|
||||
echo -e "%F{yellow}%f ${VIRTUAL_ENV:t:gs/%/%%}"
|
||||
|
@ -16,7 +16,7 @@ function reset_beam() { echo -ne '\e[5 q'; }
|
|||
|
||||
function lfwrap () {
|
||||
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
|
||||
lfub -last-dir-path="$LF_DIRFILE"
|
||||
lf-ueberzug -last-dir-path="$LF_DIRFILE"
|
||||
dir="$(cat "$LF_DIRFILE")"
|
||||
rm "$LF_DIRFILE"
|
||||
if [ -d "$dir" ]; then
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Reads file names from stdin and selects them in lf.
|
||||
|
||||
while read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
lf -remote "send select \"$file\""
|
||||
lf -remote "send toggle"
|
||||
done
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
lf "$@"
|
||||
else
|
||||
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
|
||||
lf "$@" 3>&-
|
||||
fi
|
|
@ -1,5 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
clean() {
|
||||
|
@ -11,10 +10,10 @@ if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
|||
command lf "$@"
|
||||
else
|
||||
[ ! -d "$XDG_CACHE_HOME/lf" ] && mkdir --parents "$XDG_CACHE_HOME/lf"
|
||||
export FIFO_UEBERZUG="/tmp/ueberzug-$$"
|
||||
export FIFO_UEBERZUG="$XDG_CACHE_HOME/lf/ueberzug-$$"
|
||||
mkfifo "$FIFO_UEBERZUG"
|
||||
ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
|
||||
exec 3>"$FIFO_UEBERZUG"
|
||||
trap clean HUP INT QUIT TERM PWR EXIT
|
||||
trap clean EXIT
|
||||
command lf "$@" 3>&-
|
||||
fi
|
Loading…
Reference in New Issue