1
0
Fork 0

cleanup, prepping for sixel support in lf

This commit is contained in:
Luca Bilke 2024-01-29 17:11:15 +01:00
parent 03c3857f72
commit 994453b5e2
9 changed files with 67 additions and 83 deletions

View File

@ -1,5 +1,5 @@
# Basic vars # Basic vars
set ratios 1:2:4 set ratios 1:2:6
set shellopts '-eu' set shellopts '-eu'
set ifs "\n" set ifs "\n"
set findlen 1 set findlen 1

View File

@ -5,32 +5,21 @@ RESET="\033[0m"
set -C -f set -C -f
f=$1 f=$1 w=$2 h=$3 x=$4 y=$5
w=$2
h=$3
x=$4
y=$5
image() { image() {
f=$1 f=$1 w=$2 h=$3 x=$4 y=$5
w=$2 if [ -f "$f" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
h=$3 # chafa "$f" -f sixel -s "$(($2 - 2))x$3" --animate false
x=$4 if command -V ueberzug >/dev/null 2>&1; then
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
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
fi
exit 1 exit 1
} }
video() { video() {
f=$1 f=$1 w=$2 h=$3 x=$4 y=$5
w=$2
h=$3
x=$4
y=$5
thumb="$(vidthumb "$f")" || ( thumb="$(vidthumb "$f")" || (
printf "%b" "\033[31mvidthumb script not in path\033[0m" printf "%b" "\033[31mvidthumb script not in path\033[0m"
return 1 return 1
@ -39,10 +28,10 @@ video() {
} }
text() { text() {
f=$1 f=$1 w=$2
w=$2
bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 1 bat --color=always --style=plain --pager=never --terminal-width "$((w - 2))" "$f" && exit 1
cat "$f"; exit 1 cat "$f"
exit 1
} }
run() { run() {
@ -60,7 +49,6 @@ run() {
mimetest() { mimetest() {
case "$1" in case "$1" in
text/*) text "$f" "$w" ;;
*/pdf) */pdf)
[ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE" [ ! -f "${CACHE}.jpg" ] && run pdftoppm -jpeg -f 1 -singlefile "$f" "$CACHE"
image "${CACHE}.jpg" "$w" "$h" "$x" "$y" image "${CACHE}.jpg" "$w" "$h" "$x" "$y"
@ -87,13 +75,13 @@ mimetest() {
image/*) image "$f" "$w" "$h" "$x" "$y" ;; image/*) image "$f" "$w" "$h" "$x" "$y" ;;
video/*) video "$f" "$w" "$h" "$x" "$y" ;; video/*) video "$f" "$w" "$h" "$x" "$y" ;;
*opendocument*) run odt2txt "$f" ;; *opendocument*) run odt2txt "$f" ;;
*/markdown) run lowdown -Tterm "$f" ;; */markdown) run mdcat "$f" ;;
*/html) run lynx -dump "$f" ;; */html) run lynx -dump "$f" ;;
*) return 1 ;; *) return 1 ;;
esac 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")" filerun="$(file --brief --dereference --mime-type "$f")"
mimetest "$filerun" && exit 1 mimetest "$filerun" && exit 1
@ -103,13 +91,11 @@ if command -v gio 1>/dev/null 2>&1; then
mimetest "$giorun" && exit 1 mimetest "$giorun" && exit 1
fi 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 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 esac
exit 1

View File

@ -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 [ ! -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 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

View File

@ -1,4 +1,3 @@
# vim: set ft=sh
HISTSIZE=10000000 HISTSIZE=10000000
SAVEHIST=10000000 SAVEHIST=10000000
HISTFILE="$XDG_DATA_HOME/zsh/history" HISTFILE="$XDG_DATA_HOME/zsh/history"

View File

@ -1,4 +1,4 @@
# vim: set ft=sh: #!/bin/zsh
venv_prompt() { venv_prompt() {
[[ -n ${VIRTUAL_ENV} ]] || return [[ -n ${VIRTUAL_ENV} ]] || return
echo -e "%F{yellow}%f ${VIRTUAL_ENV:t:gs/%/%%}" echo -e "%F{yellow}%f ${VIRTUAL_ENV:t:gs/%/%%}"
@ -16,7 +16,7 @@ function reset_beam() { echo -ne '\e[5 q'; }
function lfwrap () { function lfwrap () {
LF_DIRFILE="/tmp/lfdir.$(uuidgen)" LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
lfub -last-dir-path="$LF_DIRFILE" lf-ueberzug -last-dir-path="$LF_DIRFILE"
dir="$(cat "$LF_DIRFILE")" dir="$(cat "$LF_DIRFILE")"
rm "$LF_DIRFILE" rm "$LF_DIRFILE"
if [ -d "$dir" ]; then if [ -d "$dir" ]; then

View File

@ -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

9
.local/bin/lf-sixel Executable file
View File

@ -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

View File

@ -1,5 +1,4 @@
#!/bin/sh #!/bin/sh
set -e set -e
clean() { clean() {
@ -11,10 +10,10 @@ if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
command lf "$@" command lf "$@"
else else
[ ! -d "$XDG_CACHE_HOME/lf" ] && mkdir --parents "$XDG_CACHE_HOME/lf" [ ! -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" mkfifo "$FIFO_UEBERZUG"
ueberzug layer -s -p json <"$FIFO_UEBERZUG" & ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
exec 3>"$FIFO_UEBERZUG" exec 3>"$FIFO_UEBERZUG"
trap clean HUP INT QUIT TERM PWR EXIT trap clean EXIT
command lf "$@" 3>&- command lf "$@" 3>&-
fi fi

View File

@ -1,2 +1,3 @@
- [ ] [Simplify dotfile management](https://www.atlassian.com/git/tutorials/dotfiles) - [ ] [Simplify dotfile management](https://www.atlassian.com/git/tutorials/dotfiles)
- [ ] Refactor Neovim config - [ ] Refactor Neovim config
- [ ] Plumbing script! something to handle URLs, filepaths, and other stuff