-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·219 lines (202 loc) · 7.57 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·219 lines (202 loc) · 7.57 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env bash
CHAD46_DIR="$(cd "$(dirname "$0")" && pwd)"
THEMES_DIR="$CHAD46_DIR/lua/chad46/themes"
INTEG_DIR="$CHAD46_DIR/lua/chad46/integrations"
BASE46_URL="https://raw.githubusercontent.com/NvChad/base46/v3.0"
DRY_RUN=""
SYNC_MODE="all"
for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN="--dry-run" ;;
--types) SYNC_MODE="types" ;;
--themes) SYNC_MODE="themes" ;;
--integrations) SYNC_MODE="integrations" ;;
--stl) SYNC_MODE="stl" ;;
esac
done
log_add=()
log_upd=()
log_err=()
ALL_THEMES=(
aquarium ashes aylin ayu_dark ayu_light bearded-arc blossom_light carbonfox
catppuccin-latte catppuccin chadracula-evondev chadracula chadtain chocolate
darcula-dark dark_horizon decay default-dark default-light doomchad eldritch
embark everblush everforest everforest_light falcon flex-light flexoki-light
flexoki flouromachine gatekeeper github_dark github_light gruvbox
gruvbox_light gruvchad hiberbee horizon jabuti jellybeans kanagawa-dragon
kanagawa material-darker material-deep-ocean material-lighter melange
midnight_breeze mito-laser monekai monochrome mountain nano-light neofusion
nightfox nightlamp nightowl nord obsidian-ember oceanic-light oceanic-next
one_light onedark onenord onenord_light oxocarbon palenight pastelDark
pastelbeans penumbra_dark penumbra_light poimandres radium rosepine-dawn
rosepine rxyhn scaryforest seoul256_dark seoul256_light solarized_dark
solarized_light solarized_osaka starlight sunrise_breeze sweetpastel
tokyodark tokyonight tomorrow_night tundra vesper vscode_dark vscode_light
wombat yoru zenburn
)
ALL_INTEGRATIONS=(
alpha avante blankline blink blink-pair bufferline cmp codeactionmenu dap
defaults devicons diffview edgy flash git git-conflict grug_far hop
leap lsp lspsaga markview mason mini-tabline navic neogit notify
nvimtree nvshades orgmode rainbowdelimiters render-markdown semantic_tokens
syntax telescope tiny-inline-diagnostic todo treesitter trouble
vim-illuminate whichkey
)
ALL_TYPES=(
base46 themes
)
ALL_STL=(
default minimal vscode vscode_colored utils
)
fetch() {
local url="$1" result="" i
for i in 1 2 3; do
result=$(curl -sL --max-time 30 "$url" 2>/dev/null) && [[ -n "$result" ]] && { echo "$result"; return 0; }
sleep 2
done
echo ""
}
sync_dir() {
local type="$1" dst="$2"
shift 2
local names=("$@")
echo "=== Syncing $type ==="
local add=0 upd=0 err=0
for name in "${names[@]}"; do
echo -n " $name ... "
local url="$BASE46_URL/lua/base46/$type/$name.lua"
local content; content=$(fetch "$url")
[[ -z "$content" ]] && { log_err+=("$type: $name"); echo "FAILED"; ((err++)); [[ "$type" == "themes" ]] && gen_cs "$name"; continue; }
if [[ "$type" == "themes" ]]; then
content=$(echo "$content" | grep -v 'require("base46").override_theme')
content="${content%"${content##*[![:space:]]}"}"
if ! echo "$content" | grep -q '^return M$'; then content="$content"$'\n\nreturn M\n'; fi
fi
if [[ "$type" == "integrations" && "$name" == "devicons" ]]; then
local tmp=$(mktemp)
printf '%s\n' "$content" > "$tmp"
command -v nvim &>/dev/null && nvim --headless --noplugin \
-c "let g:fixup_file='$tmp'" \
-c "luafile $CHAD46_DIR/fixup_devicons.lua" -c "qa!" 2>/dev/null
content=$(<"$tmp")
rm -f "$tmp"
fi
local f="$dst/$name.lua"
if [[ -f "$f" ]]; then
local old; old=$(<"$f")
[[ "$old" == "$content" ]] && { echo "skip"; [[ "$type" == "themes" ]] && gen_cs "$name"; continue; }
log_upd+=("$type: $name"); echo "updated"; ((upd++))
else
log_add+=("$type: $name"); echo "added"; ((add++))
fi
[[ "$DRY_RUN" != "--dry-run" ]] && printf '%s\n' "$content" > "$f"
[[ "$type" == "themes" ]] && gen_cs "$name"
done
echo " total: ${#names[@]}, added: $add, updated: $upd, errors: $err"
}
TYPES_DIR="$CHAD46_DIR/chad46_types"
UI_URL="https://raw.githubusercontent.com/NvChad/ui/v3.0"
sync_types() {
local dst="$1"
shift 1
local names=("$@")
echo "=== Syncing types ==="
local add=0 upd=0 err=0
for name in "${names[@]}"; do
echo -n " $name ... "
local url="$UI_URL/nvchad_types/$name.lua"
local content; content=$(fetch "$url")
[[ -z "$content" ]] && { log_err+=("types: $name"); echo "FAILED"; ((err++)); continue; }
local f="$dst/$name.lua"
if [[ -f "$f" ]]; then
local old; old=$(<"$f")
[[ "$old" == "$content" ]] && { echo "skip"; continue; }
log_upd+=("types: $name"); echo "updated"; ((upd++))
else
log_add+=("types: $name"); echo "added"; ((add++))
fi
[[ "$DRY_RUN" != "--dry-run" ]] && printf '%s\n' "$content" > "$f"
done
echo " total: ${#names[@]}, added: $add, updated: $upd, errors: $err"
}
STL_URL="https://raw.githubusercontent.com/NvChad/ui/v3.0/lua/nvchad/stl"
STL_DIR="$CHAD46_DIR/lua/chad46/adapters/nvchad_stl"
sync_stl() {
local dst="$1"
shift 1
local names=("$@")
echo "=== Syncing stl ==="
local upd=0 err=0
for name in "${names[@]}"; do
echo -n " $name ... "
local url="$STL_URL/$name.lua"
local content; content=$(fetch "$url")
[[ -z "$content" ]] && { log_err+=("stl: $name"); echo "FAILED"; ((err++)); continue; }
local tmp=$(mktemp)
printf '%s\n' "$content" > "$tmp"
command -v nvim &>/dev/null && nvim --headless --noplugin \
-c "let g:fixup_file='$tmp'" \
-c "let g:fixup_name='$name'" \
-c "luafile $CHAD46_DIR/fixup_stl.lua" -c "qa!" 2>/dev/null
content=$(<"$tmp")
rm -f "$tmp"
local f="$dst/$name.lua"
if [[ -f "$f" ]]; then
local old; old=$(<"$f")
[[ "$old" == "$content" ]] && { echo "skip"; continue; }
log_upd+=("stl: $name"); echo "updated"
else
log_add+=("stl: $name"); echo "added"
fi
[[ "$DRY_RUN" != "--dry-run" ]] && printf '%s\n' "$content" > "$f"
done
echo " total: ${#names[@]}, updated: $upd, errors: $err"
}
generate_full_cs() {
command -v nvim &>/dev/null || return 0
mkdir -p "$CHAD46_DIR/colors" "$CHAD46_DIR/autoload/airline/themes" "$CHAD46_DIR/autoload/lightline/colorscheme"
echo "=== Generating Vim colorschemes & airline themes ==="
nvim --headless --noplugin -c "luafile $CHAD46_DIR/generate_vim.lua" -c "qa!" 2>&1
echo " done"
}
gen_cs() { return 0; }
# Fix devicons.lua: correct DevIcon group names to PascalCase
# so they match nvim-web-devicons' naming convention.
fixup_devicons() {
local f="$INTEG_DIR/devicons.lua"
[[ ! -f "$f" ]] && return 0
[[ "$DRY_RUN" == "--dry-run" ]] && return 0
nvim --headless --noplugin \
-c "let g:fixup_file='$f'" \
-c "luafile $CHAD46_DIR/fixup_devicons.lua" -c "qa!" 2>&1
}
main() {
echo "chad46 sync${DRY_RUN:+ (DRY RUN)} [$SYNC_MODE]"
mkdir -p "$THEMES_DIR" "$INTEG_DIR" "$TYPES_DIR"
if [[ "$SYNC_MODE" == "all" || "$SYNC_MODE" == "themes" ]]; then
local theme_before=$(( ${#log_add[@]} + ${#log_upd[@]} ))
sync_dir "themes" "$THEMES_DIR" "${ALL_THEMES[@]}"
local theme_after=$(( ${#log_add[@]} + ${#log_upd[@]} ))
if (( theme_after > theme_before )); then
generate_full_cs
fi
echo ""
fi
if [[ "$SYNC_MODE" == "all" || "$SYNC_MODE" == "integrations" ]]; then
sync_dir "integrations" "$INTEG_DIR" "${ALL_INTEGRATIONS[@]}"
echo ""
fi
if [[ "$SYNC_MODE" == "all" || "$SYNC_MODE" == "types" ]]; then
sync_types "$TYPES_DIR" "${ALL_TYPES[@]}"
echo ""
fi
if [[ "$SYNC_MODE" == "all" || "$SYNC_MODE" == "stl" ]]; then
sync_stl "$STL_DIR" "${ALL_STL[@]}"
echo ""
fi
echo "Errors: ${#log_err[@]}"
for v in "${log_err[@]}"; do echo " ! $v"; done
[[ ${#log_err[@]} -gt 0 ]] && echo "Some files failed (see above)." && exit 1
exit 0
}
main