summaryrefslogtreecommitdiff
path: root/.config
diff options
context:
space:
mode:
Diffstat (limited to '.config')
-rwxr-xr-x.config/lf/scope157
-rw-r--r--.config/sxhkd/sxhkdrc8
-rw-r--r--.config/xresources/workstation7
-rw-r--r--.config/zsh/.zshrc2
4 files changed, 117 insertions, 57 deletions
diff --git a/.config/lf/scope b/.config/lf/scope
index cc55669..f396519 100755
--- a/.config/lf/scope
+++ b/.config/lf/scope
@@ -1,56 +1,123 @@
#!/bin/sh
-# File preview handler for lf.
-
set -C -f
-IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}"
-
-image() {
- 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" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG"
- else
- mediainfo "$6"
- fi
+IFS="$(printf '%b_' '\n')"
+IFS="${IFS%_}"
+
+PREVIEW_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/lf"
+PREVIEW_WIDTH=600 # px
+
+# TODO: Render in the original width when it's smaller than PREVIEW_WIDTH
+
+# PrefixGen: generates a hash prefix for the given file
+# This is a unique identifier for the file to preview
+PrefixGen() {
+ # The file path is hashed instead of the file itself since large files
+ # can take a long time to hash and the file path is usually enough to
+ # uniquely identify the file. Also, the suffix is used to determine if
+ # the preview is outdated (which removes the need to hash the file).
+ readlink -f "$1" | sha256sum | cut -d' ' -f1
}
-ifub() {
- [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1
+# SuffixGen: generates a hash suffix for the given file
+# This suffix is used to determine if the preview is outdated
+SuffixGen() {
+ stat -Lc "%Y" "$1"
}
-# Note that the cache file name is a function of file information, meaning if
-# an image appears in multiple places across the machine, it will not have to
-# be regenerated once seen.
+# Prevent recursive thumbnails (if the file ends in .six)
+[ "${1##*.}" = "six" ] && cat "$1" && exit 1
case "$(file --dereference --brief --mime-type -- "$1")" in
- image/avif) CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
- [ ! -f "$CACHE" ] && convert "$1" "$CACHE.jpg"
- image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;;
- image/vnd.djvu)
- CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
- [ ! -f "$CACHE" ] && djvused "$1" -e 'select 1; save-page-with /dev/stdout' | convert -density 200 - "$CACHE.jpg" > /dev/null 2>&1
- image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;;
- image/*) image "$1" "$2" "$3" "$4" "$5" "$1" ;;
- text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;;
- text/troff) man ./ "$1" | col -b ;;
- text/* | */xml | application/json | application/x-ndjson) bat --terminal-width "$(($4-2))" -f "$1" ;;
- audio/* | application/octet-stream) mediainfo "$1" || exit 1 ;;
- video/* )
- CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
- [ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
- image "$CACHE" "$2" "$3" "$4" "$5" "$1"
- ;;
- */pdf)
- CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
- [ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
- image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1"
- ;;
- */epub+zip|*/mobi*)
- CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | cut -d' ' -f1)"
- [ ! -f "$CACHE.jpg" ] && gnome-epub-thumbnailer "$1" "$CACHE.jpg"
- image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1"
- ;;
- application/*zip) atool --list -- "$1" ;;
- *opendocument*) odt2txt "$1" ;;
- application/pgp-encrypted) gpg -d -- "$1" ;;
+text/html)
+ lynx -width="$4" -display_charset=utf-8 -dump "$1"
+ ;;
+text/troff)
+ man ./ "$1" | col -b
+ ;;
+text/* | */xml | application/json | application/x-ndjson)
+ bat --terminal-width "$(($4 - 2))" -f "$1"
+ ;;
+audio/* | application/octet-stream)
+ mediainfo "$1" || exit 1
+ ;;
+image/vnd.djvu)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ djvused "$1" -e 'select 1; save-page-with /dev/stdout' |
+ convert djvu:- ppm:- |
+ img2sixel -S -E size -q high -w $PREVIEW_WIDTH -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+image/webp)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ dwebp "$1" -tiff -o - | img2sixel -S -E size -q high -w $PREVIEW_WIDTH -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+image/heic)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ convert "$1" ppm:- |
+ img2sixel -S -E size -q high -w $PREVIEW_WIDTH -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+image/*)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ img2sixel -S -E size -q high -w $PREVIEW_WIDTH "$1" -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+*/pdf)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ pdftocairo -singlefile -scale-to-x $PREVIEW_WIDTH -scale-to-y -1 -jpeg "$1" - |
+ img2sixel -S -E size -q high -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+video/*)
+ prefix="$(PrefixGen "$1")"
+ suffix="$(SuffixGen "$1")"
+ filename="$prefix-$suffix"
+ [ ! -f "$PREVIEW_DIR/$filename.six" ] && {
+ rm -f "$PREVIEW_DIR/$prefix-*"
+ ffmpegthumbnailer -i "$1" -s 0 -c jpeg -f -o - |
+ img2sixel -S -E size -q high -w $PREVIEW_WIDTH -o "$PREVIEW_DIR/$filename.six"
+ }
+ cat "$PREVIEW_DIR/$filename.six"
+ ;;
+application/*zip)
+ atool --list -- "$1"
+ ;;
+*spreadsheetml.sheet)
+ xlsx2csv -s 1 "$1" | bat --terminal-width "$(($4 - 2))" -l 'csv'
+ ;;
+*opendocument*)
+ odt2txt "$1"
+ ;;
+application/pgp-encrypted)
+ gpg -d -- "$1"
+ ;;
esac
+
exit 1
diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc
index 5e78558..31f10df 100644
--- a/.config/sxhkd/sxhkdrc
+++ b/.config/sxhkd/sxhkdrc
@@ -146,8 +146,11 @@ super + e
XF86WLAN
killall nmtui || dropdowntoggle network nmtui
## TUI Audio Mixer (pulsemixer)
+super + shift + p
+ killall pulsemixer || dropdowntoggle audio pulsemixer
+## Display selector (connect to projector/secondary monitor)
super + p
- killall pulsemixer || dropdowntoggle bluetooth pulsemixer
+ displayselect
## TODOs (orgmode-nvim)
super + space
dropdowntoggle orgmode nvim +"Neorg index"
@@ -165,9 +168,6 @@ super + r
## Application Launcher
super + d
j4-dmenu-desktop
-## Display Layout Selector
-super + shift + d
- displayselect
## Emoji & Font-Awesome Selector
alt + grave
emoji-copy
diff --git a/.config/xresources/workstation b/.config/xresources/workstation
deleted file mode 100644
index 2d6d9c9..0000000
--- a/.config/xresources/workstation
+++ /dev/null
@@ -1,7 +0,0 @@
-Xft.dpi: 96
-Xft.autohing: 0
-Xft.lcdfilter: lcddefault
-Xft.hintstyle: hintfull
-Xft.hinting: 1
-Xft.antialias: 1
-Xft.rgba: rgb
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc
index ddee6ea..d0cd6a7 100644
--- a/.config/zsh/.zshrc
+++ b/.config/zsh/.zshrc
@@ -91,7 +91,7 @@ source $HOME/.cache/shell-vars
lfcd () {
tmp="$(mktemp -uq)"
trap 'rm -f $tmp >/dev/null 2>&1 && trap - HUP INT QUIT TERM PWR EXIT' HUP INT QUIT TERM PWR EXIT
- lfub -last-dir-path="$tmp" "$@"
+ lf -single -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"