-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOOTSTRAP.sh
48 lines (36 loc) · 2.4 KB
/
BOOTSTRAP.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
#!/usr/bin/env zsh
set -e # abort when any command errors (prevents self-removing at the end)
#───────────────────────────────────────────────────────────────────────────────
# VALUES
# plugin name is the same as the git repo name and can therefore be inferred
repo=$(git remote -v | head -n1 | sed -e 's/\.git.*//' -e 's/.*:\(.*\) .*/\1/')
name=$(echo "$repo" | cut -d/ -f2)
name_short=$(echo "$name" | sed -e 's/.nvim$//' -e 's/^nvim-//')
year=$(date +"%Y")
# desc can be inferred from github description (not using jq for portability)
desc=$(curl -sL "https://api.github.com/repos/$repo" |
grep --max-count=1 "description" | cut -d'"' -f4)
#───────────────────────────────────────────────────────────────────────────────
# PLACEHOLDERS
# INFO macOS' sed requires `sed -i ''`, remove the `''` when on Linux
function replacePlaceholders() {
LC_ALL=C # prevent byte sequence error
this_file=$(basename "$0")
find . -type f -not -path '*/\.git/*' -not -name ".DS_Store" -not -name "$this_file" -exec \
sed -i '' "s|$1|$2|g" {} \;
}
replacePlaceholders "PLACEHOLDER_plugin_name" "$name"
replacePlaceholders "PLACEHOLDER_plugin_name_short" "$name_short"
replacePlaceholders "PLACEHOLDER_plugin_desc" "$desc"
replacePlaceholders "PLACEHOLDER_year" "$year"
replacePlaceholders "PLACEHOLDER_plugin_repo" "$repo"
#───────────────────────────────────────────────────────────────────────────────
# FILES
mv "./lua/PLACEHOLDER_plugin_name_short" "./lua/$name_short"
# creating file instead of renaming it, since an existing file would trigger the
# github actions
mkdir "./doc" && touch "./doc/$name_short.txt"
#───────────────────────────────────────────────────────────────────────────────
git add --all && git commit -m "init: bootstrap"
print "\e[1;32mSuccess.\e[0m"
rm -- "$0" # make this script delete itself