summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-04-27 09:42:41 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2024-04-27 09:42:41 -0400
commitd4b26da65c20df3559daa6379c27fef3dcbc400f (patch)
tree4555c80ed1ab6a187312e33be0487e1732e8fd88
parent3c823c638e3de31332b8966a2f1712c6bbb8d2b5 (diff)
parent26ec2e5dc6e8c2369ecb34b642db546327a8b7dd (diff)
Merge branch 'master' of github.com:ChausseBenjamin/dotfiles
-rw-r--r--.Xresources5
-rwxr-xr-x.config/lf/scope157
-rw-r--r--.config/sxhkd/sxhkdrc8
-rw-r--r--.config/xresources/workstation7
-rw-r--r--.config/zsh/.zshrc2
-rwxr-xr-x.local/bin/compiler2
-rwxr-xr-x.local/bin/dwmbar/dwmb-eselect2
-rwxr-xr-x.local/bin/dwmbar/dwmb-layout2
-rwxr-xr-x.local/bin/dwmbar/dwmb-time1
-rwxr-xr-x.local/bin/lfub25
-rwxr-xr-x.local/bin/previewclean10
-rwxr-xr-x.local/bin/updatestatus2
-rw-r--r--.profile5
-rw-r--r--.xinitrc4
14 files changed, 141 insertions, 91 deletions
diff --git a/.Xresources b/.Xresources
index 5068056..76696db 100644
--- a/.Xresources
+++ b/.Xresources
@@ -41,6 +41,11 @@
! No support for cursor text coloring; would be #1e232b.
! No support for bold coloring; would be #626a73.
+dmenu.background: #1b1d1b
+dmenu.foreground: #447a6c
+dmenu.color11: #7d4b23
+dmenu.color0: #1b1d1b
+
!other
*.alpha: 0.80
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"
diff --git a/.local/bin/compiler b/.local/bin/compiler
index 220b4a9..e6a6db3 100755
--- a/.local/bin/compiler
+++ b/.local/bin/compiler
@@ -28,7 +28,7 @@ case "$file" in
# *\.gd) groffdown "$file" | refer -PS -e "$REFERBIB" | groff -me -ms -kejpt -T pdf > "$base".pdf ;;
*\.mom) refer -PS -e -p"$REFERBIB" "$file" | groff -mom -kejpt -T pdf >"$base".pdf ;;
*\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;;
-*\.rnw) Rscript -e "knitr::knit2pdf('""$file""')" ;;
+*\.rnw) Rscript -e "knitr::knit2pdf('""$file""',compiler='xelatex')" ;;
*\.tex) textype "$file" ;;
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
*config.h) make && sudo make install ;;
diff --git a/.local/bin/dwmbar/dwmb-eselect b/.local/bin/dwmbar/dwmb-eselect
index 2d83c8b..24372b4 100755
--- a/.local/bin/dwmbar/dwmb-eselect
+++ b/.local/bin/dwmbar/dwmb-eselect
@@ -1,6 +1,6 @@
#!/bin/sh
-icon=""
+icon="  "
total="$(eselect news count all)"
unread="$(eselect news count new)"
diff --git a/.local/bin/dwmbar/dwmb-layout b/.local/bin/dwmbar/dwmb-layout
index 9416a2e..1455398 100755
--- a/.local/bin/dwmbar/dwmb-layout
+++ b/.local/bin/dwmbar/dwmb-layout
@@ -1,3 +1,3 @@
#!/bin/sh
-echo " $(cat $HOME/.cache/layout)"
+echo "  $(cat "$HOME/.cache/layout")"
diff --git a/.local/bin/dwmbar/dwmb-time b/.local/bin/dwmbar/dwmb-time
index fc17227..bbd6585 100755
--- a/.local/bin/dwmbar/dwmb-time
+++ b/.local/bin/dwmbar/dwmb-time
@@ -1,4 +1,3 @@
#!/bin/sh
date +"  %H:%M "
-
diff --git a/.local/bin/lfub b/.local/bin/lfub
deleted file mode 100755
index 43a7ef9..0000000
--- a/.local/bin/lfub
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-# This is a wrapper script for lb that allows it to create image previews with
-# ueberzug. This works in concert with the lf configuration file and the
-# lf-cleaner script.
-
-set -e
-
-cleanup() {
- exec 3>&-
- rm "$FIFO_UEBERZUG"
-}
-
-if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
- lf "$@"
-else
- [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf"
- export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$"
- mkfifo "$FIFO_UEBERZUG"
- ueberzug layer -s -p json <"$FIFO_UEBERZUG" &
- exec 3>"$FIFO_UEBERZUG"
- trap cleanup HUP INT QUIT TERM PWR EXIT
- lf "$@" 3>&-
- killall ueberzug >/dev/null 2>&1
-fi
diff --git a/.local/bin/previewclean b/.local/bin/previewclean
new file mode 100755
index 0000000..8b0a570
--- /dev/null
+++ b/.local/bin/previewclean
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+threshold="200000" # 200 MB
+previewdir="${XDG_CACHE_HOME:-$HOME/.cache}/lf"
+
+# Check if the total size of the preview directory exceeds the threshold
+# and remove the last viewed file until it doesn't
+while [ "$(du -s "$previewdir" | cut -f1)" -gt "$threshold" ]; do
+ rm -f "$(find "$previewdir" -type f -printf '%T+ %p\n' | sort | head -n1 | cut -d' ' -f2)"
+done
diff --git a/.local/bin/updatestatus b/.local/bin/updatestatus
index aedbb84..7000608 100755
--- a/.local/bin/updatestatus
+++ b/.local/bin/updatestatus
@@ -4,7 +4,7 @@ time="$($1)"
[ -z "$1" ] && time="5"
# Prevent "no such file or directory" on 1st run
-genlop -c >/tmp/genlop
+clear && genlop -c >/tmp/genlop
while true; do
cat /tmp/genlop
diff --git a/.profile b/.profile
index 0055553..b86c829 100644
--- a/.profile
+++ b/.profile
@@ -19,13 +19,14 @@ export DISTRIB_ID=arch
export DISTRIB_RELEASE=$(uname -r)
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
+export XDG_CACHE_HOME=$HOME/.cache
export R_PROFILE_USER=$HOME/.config/R/Rprofile
export ZDOTDIR=$XDG_CONFIG_HOME/zsh
export TEXMFHOME=$XDG_DATA_HOME/texmf
export TEXSRC=$HOME/.local/src/sherbrooke-tex
# Applications
-export EDITOR=$(which nvim)
+export EDITOR=/usr/bin/nvim
export READER=/usr/bin/zathura
export TERMINAL=/usr/local/bin/st
export TERM=/usr/local/bin/st
@@ -46,7 +47,7 @@ shortcutgen
aliasgen
# Import shortcut ENV variables
-source "$HOME/.cache/env-shortcuts"
+source "$XDG_CACHE_HOME/env-shortcuts"
# Ensure XDG_RUNTIME_DIR is set
if test -z "$XDG_RUNTIME_DIR"; then
diff --git a/.xinitrc b/.xinitrc
index c98de06..5e0df62 100644
--- a/.xinitrc
+++ b/.xinitrc
@@ -3,8 +3,8 @@ sxhkd &
dunst &
unclutter &
picom -b &
-echo us >$HOME/.cache/layout
-xrdb -load $HOME/.Xresources
+echo us >"$HOME/.cache/layout"
+xrdb -load "$HOME/.Xresources"
flashfocus -n 30 -t 150 -l never -o 0.75 -v ERROR &
dwmblocks &
remaps &