-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathswitch.sh
More file actions
executable file
·161 lines (142 loc) · 3.88 KB
/
switch.sh
File metadata and controls
executable file
·161 lines (142 loc) · 3.88 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
set -euo pipefail
check_macos() {
local os_name
os_name=$(uname -s)
if [ "$os_name" = "Darwin" ]; then
return 0
else
return 1
fi
}
kill_process() {
local pid=${1:-}
if [ -n "$pid" ]; then
kill -SIGUSR1 "$pid"
fi
}
safe_perl() {
local pattern=$1
local file=$2
if [ -f "$file" ]; then
perl -i -pe "$pattern" "$file"
fi
}
nvim_setting=~/.config/nvim/lua/user/settings.lua
chadrc=~/.config/nvim/lua/chadrc.lua
vscode_setting=~/.config/Code/User/settings.json
ghostty_setting=~/.config/ghostty/config
trae_setting=""
kitty_setting=~/.config/kitty/kitty.conf
tmux_setting=~/.tmux.conf
mode_state_file=~/.mode_switch_state
if check_macos; then
vscode_setting=~/Library/'Application Support'/Code/User/settings.json
ghostty_setting=~/Library/'Application Support'/com.mitchellh.ghostty/config
trae_setting=~/Library/'Application Support'/'Trae CN'/User/settings.json
fi
set_neovim_background() {
local background=$1
local servers
if check_macos; then
servers=$(lsof -U 2>/dev/null | awk '/nvim/ && /\/var\/folders/ && !/fzf/ {print $8}')
else
servers=$(lsof -U 2>/dev/null | awk '/nvim/ && /\/run\/user/ && !/fzf/ {print $9}')
fi
if [ -f "$chadrc" ]; then
if [ -n "$servers" ]; then
for server in $servers; do
nvim --server "$server" --remote-send ":lua require('base46').toggle_theme()<CR>"
done
else
if [ "$background" = "dark" ]; then
safe_perl 's/theme = "penumbra_light"/theme = "everforest"/' "$chadrc"
else
safe_perl 's/theme = "everforest"/theme = "penumbra_light"/' "$chadrc"
fi
fi
else
if [ "$background" = "dark" ]; then
safe_perl 's/settings\["background"\] = "light"/settings\["background"\] = "dark"/' "$nvim_setting"
else
safe_perl 's/settings\["background"\] = "dark"/settings\["background"\] = "light"/' "$nvim_setting"
fi
if [ -n "$servers" ]; then
for server in $servers; do
nvim --server "$server" --remote-send ":set background=$background<CR>"
done
fi
fi
}
switch_mode() {
local input=$1
case "$input" in
light)
# safe_perl 's/mocha/latte/' "$kitty_setting"
# safe_perl 's/Mocha/Latte/' "$ghostty_setting"
# osascript ~/clone/dotfiles/macOS/ghostty-reload-config.scpt
# kill_process "$(pgrep kitty)"
safe_perl 's/everforest/penu/' "$tmux_setting"
[ -n "$trae_setting" ] && safe_perl 's/"workbench.colorTheme": "Dark"/"workbench.colorTheme": "Light"/' "$trae_setting"
safe_perl 's/"workbench.colorTheme": "Default Dark Modern"/"workbench.colorTheme": "Default Light Modern"/' "$vscode_setting"
set_neovim_background "light"
~/.local/bin/iterm-theme penumbra_light
tmux source-file "$tmux_setting"
;;
dark)
# safe_perl 's/latte/mocha/' "$kitty_setting"
# safe_perl 's/Latte/Mocha/' "$ghostty_setting"
# osascript ~/clone/dotfiles/macOS/ghostty-reload-config.scpt
# kill_process "$(pgrep kitty)"
safe_perl 's/penu/everforest/' "$tmux_setting"
[ -n "$trae_setting" ] && safe_perl 's/"workbench.colorTheme": "Light"/"workbench.colorTheme": "Dark"/' "$trae_setting"
safe_perl 's/"workbench.colorTheme": "Default Light Modern"/"workbench.colorTheme": "Default Dark Modern"/' "$vscode_setting"
set_neovim_background "dark"
~/.local/bin/iterm-theme everforest_dark_low
tmux source-file "$tmux_setting"
;;
*)
echo "Invalid mode: $input" >&2
return 1
;;
esac
}
get_current_mode() {
if [ -f "$mode_state_file" ]; then
cat "$mode_state_file"
else
echo "light"
fi
}
set_current_mode() {
printf '%s
' "$1" >"$mode_state_file"
}
toggle_mode() {
local current_mode
current_mode=$(get_current_mode)
if [ "$current_mode" = "light" ]; then
set_current_mode "dark"
switch_mode "dark"
else
set_current_mode "light"
switch_mode "light"
fi
}
main() {
local mode=${1:-toggle}
case "$mode" in
toggle)
toggle_mode
;;
light | dark)
set_current_mode "$mode"
switch_mode "$mode"
;;
*)
echo "Usage: $0 {light|dark|toggle}" >&2
exit 1
;;
esac
}
main "$@"