-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-theme.sh
executable file
·96 lines (80 loc) · 2.24 KB
/
change-theme.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -ueo pipefail
warn() {
echo "[33m$* [30m[m"
}
if [ -z "${1:-}" ]; then
# shellcheck disable=SC2010
STOW_TARGET=$(\
ls | grep theme- | grep "$(./current-workstation.sh | sed 's/workstation-//')" | fzf --prompt="select theme:" \
) || (
warn "Canceled"
exit 1
)
else
STOW_TARGET=$1
fi
CURRENT_THEME=$(./current-theme.sh) || CURRENT_THEME=''
if [[ -n ${CURRENT_THEME} ]] ; then
warn "== Unstowing the current theme..."
exit_code=0
result=$(stow -D "$(./current-theme.sh)" 2>&1) || exit_code=$?
if [[ $exit_code -gt 0 ]] ; then
echo "$result"
exit $exit_code
else
echo "$result" | grep -v -e "Absolute/relative mismatch between Stow dir dotfiles and path" || true
fi
fi
warn "== Stowing the new theme..."
stow "$STOW_TARGET"
set +ueo pipefail
warn "== Applying the new theme..."
warn "-- Applying profile..."
# shellcheck source=$HOME/.profile disable=SC1091
source ~/.profile
if ! which xrdb ; then
warn "!! xrdb is not installed"
else
warn "-- Applying xrdb..."
xrdb -merge "$HOME"/.Xresources
fi
if ! which awesome-client ; then
warn "!! awesome is not installed"
else
if [[ -z "${NORESTART:-}" ]] ; then
warn "-- Restarting AwesomeWM..."
echo "awesome.restart()" | awesome-client || true
fi
fi
if ! which tmux > /dev/null ; then
warn "!! tmux is not installed"
else
warn "-- Applying env inside tmux sessions..."
IFS=$'\n'
for line in $(env | grep -e ^TMUX_ -e ^FISH_ -e ^TERM_ | grep -v TMUX_PANE) ; do
# shellcheck disable=SC2046
key=$(cut -d'=' -f1 <<< "$line")
value=$(cut -d'=' -f2 <<< "$line")
if [[ -z "${value:-}" ]] ; then
tmux setenv -g "${key}" ''
else
tmux setenv -g "${key}" "${value:-}"
fi
done;
warn "-- Reloading tmux..."
tmux source-file ~/.tmux.conf
fi
warn "-- Reloading fish..."
fish -c reload_fish
# move to the end or debug this? https://github.com/gnotclub/xst/blob/1df15396883870cc9dfd19cbddc0a88e81849fb2/src/st.c#L4671
warn "-- Reloading xst..."
pgrep "^xst\$" | xargs kill -s USR1
if [[ -f ~/.apply_theme.sh ]] ; then
warn "-- Executing '~/.apply_theme.sh' script..."
~/.apply_theme.sh
fi
echo
echo "====================================================="
echo "== Theme was changed to '${STOW_TARGET}'"
echo "====================================================="