-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme-picker.sh
More file actions
executable file
·69 lines (54 loc) · 1.7 KB
/
theme-picker.sh
File metadata and controls
executable file
·69 lines (54 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
THEME_DIR="$HOME/stuff/themes"
PREVIEW_IMG="$HOME/.cache/fzf_theme_preview.png"
DEBOUNCE_FILE="/tmp/fzf_theme_debounce"
# gather themes (.sh files) and sort them alphabetically
mapfile -t THEMES < <(find "$THEME_DIR" -maxdepth 1 -type f -name '*.sh' -printf '%f\n' | sort)
cleanup() {
pkill -f "feh --title fzf-theme-preview" 2>/dev/null
rm -f "$PREVIEW_IMG"
rm -f "$DEBOUNCE_FILE"
}
trap cleanup EXIT
[ ${#THEMES[@]} -eq 0 ] && {
echo "No themes found in $THEME_DIR"
exit 1
}
# initialize preview with first theme
basename="${THEMES[0]%.sh}"
ln -sf "$THEME_DIR/$basename.png" "$PREVIEW_IMG"
feh --title fzf-theme-preview --geometry 645x589+600+250 --scale-down --image-bg black --reload 1 --no-menus "$PREVIEW_IMG" &
FEH_PID=$!
preview_cmd() {
local scriptname="$1"
local base="${scriptname%.sh}"
local imgpath="$THEME_DIR/$base.png"
[ ! -f "$imgpath" ] && return
local now=$(date +%s%3N)
if [ -f "$DEBOUNCE_FILE" ]; then
local last_update
last_update=$(cat "$DEBOUNCE_FILE")
local diff=$((now - last_update))
if (( diff < 200 )); then
return
fi
fi
ln -sf "$imgpath" "$PREVIEW_IMG"
echo "$now" > "$DEBOUNCE_FILE"
}
export -f preview_cmd
export THEME_DIR
export PREVIEW_IMG
export DEBOUNCE_FILE
selected=$(printf '%s\n' "${THEMES[@]}" | fzf \
--height=100% --border --prompt=" Choose theme: " \
--preview "bash -c 'preview_cmd {}'" \
--preview-window=right:0%:wrap \
--bind "enter:accept" \
--cycle)
if [ -n "$selected" ]; then
CURRENT_THEME=$(<"$THEME_DIR/$selected")
bash "$THEME_DIR/$selected"
bash "$HOME/stuff/dev/bash/scripts/pywal-to-spicetify.sh"
fi
cleanup