-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__foot_shell
executable file
·60 lines (53 loc) · 2.76 KB
/
__foot_shell
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
#!/usr/bin/env sh
# vim: ft=sh ts=4 sw=4 sts=4 et :
# Foot shell program executed at each launch to reload colors on config change
# Source: https://codeberg.org/dnkl/foot/issues/708#issuecomment-1635542
MAIN_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/foot/foot.ini"
THEME_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/foot/theme.ini"
while inotifywait -qe create,modify,attrib "$MAIN_CONFIG" >/dev/null 2>&1; do
# Set term 16 colors
# ex: 'regular0=0b0b0b'
sed -n -r 's/^\w*(regular|bright)([0-9])=([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}).*/\1 \2 \3 \4 \5/p' "$THEME_CONFIG" |
while read -r color_type idx r g b; do
if [ "$color_type" = 'bright' ]; then
idx=$(( idx + 8 ))
fi
printf '\033]4;%s;rgb:%s/%s/%s\033\\' "$idx" "$r" "$g" "$b" 2>/dev/null
done
# Set foreground/background colors
# ex: 'foreground=ffffff'
# 'background=0b0b0b'
sed -n -r 's/^\w*foreground=([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}).*/\1 \2 \3/p' "$THEME_CONFIG" |
while read -r r g b; do
printf '\033]10;rgb:%s/%s/%s\033\\' "$r" "$g" "$b" 2>/dev/null
done
sed -n -r 's/^\w*background=([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}).*/\1 \2 \3/p' "$THEME_CONFIG" |
while read -r r g b; do
printf '\033]11;rgb:%s/%s/%s\033\\' "$r" "$g" "$b" 2>/dev/null
done
# Set cursor colors
# ex: 'color=181819 e2e2e3'
sed -n -r 's/^\w*color=([0-9a-fA-F]{6})\s+([0-9a-fA-F]{6}).*/\1 \2/p' "$THEME_CONFIG" |
while read -r cursor_fg cursor_bg; do
cursor_bg_r=$(printf '%s' "$cursor_bg" | cut -c1-2)
cursor_bg_g=$(printf '%s' "$cursor_bg" | cut -c3-4)
cursor_bg_b=$(printf '%s' "$cursor_bg" | cut -c5-6)
cursor_fg_r=$(printf '%s' "$cursor_fg" | cut -c1-2)
cursor_fg_g=$(printf '%s' "$cursor_fg" | cut -c3-4)
cursor_fg_b=$(printf '%s' "$cursor_fg" | cut -c5-6)
printf '\033]12;rgb:%s/%s/%s\033\\' "$cursor_bg_r" "$cursor_bg_g" "$cursor_bg_b" 2>/dev/null
printf '\033]13;rgb:%s/%s/%s\033\\' "$cursor_fg_r" "$cursor_fg_g" "$cursor_fg_b" 2>/dev/null
done
# Set selection colors
# ex: 'selection-foreground=3b3e48'
# 'selection-background=e2e2e3'
sed -n -r 's/^\w*selection-foreground=([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}).*/\1 \2 \3/p' "$THEME_CONFIG" |
while read -r r g b; do
printf '\033]19;rgb:%s/%s/%s\033\\' "$r" "$g" "$b" 2>/dev/null
done
sed -n -r 's/^\w*selection-background=([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2}).*/\1 \2 \3/p' "$THEME_CONFIG" |
while read -r r g b; do
printf '\033]17;rgb:%s/%s/%s\033\\' "$r" "$g" "$b" 2>/dev/null
done
done &
exec "$SHELL"