-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-readme.sh
executable file
·101 lines (84 loc) · 1.88 KB
/
gen-readme.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
97
98
99
100
101
#!/usr/bin/env bash
SCRIPTS_ROOT=${SCRIPTS_ROOT:=$(
cd $(dirname $0)
pwd
)}
source $SCRIPTS_ROOT/common.zsh
readme="$SCRIPTS_ROOT/README.md"
cat >"$readme" <<EOM
# Rainbow Watcher's personal scripts
## Quick Start
Write it to your \`~/.zshrc\` to enable those scripts.
\`\`\`shell
SCRIPTS_ROOT="/path/to/project/location"
# if you want to enable proxy
HTTP_PROXY_ADDR=http://127.0.0.1:12345
source \$SCRIPTS_ROOT/main.zsh all
\`\`\`
> [!NOTE]
>
> - Remember to change the proxy port number to you own.
> - this repository used some third-party packages: \`zoxide\`, \`eza\`, \`ripgrep\`, \`fnm\`, \`node\`, \`jq\`, \`gum\`...etc
>
> \`\`\`shell
> brew install zoxide eza ripgrep fnm node jq gum
> \`\`\`
## Alias
EOM
alias_localtion="$SCRIPTS_ROOT/alias"
files=($(ls $alias_localtion/*))
for item in "${files[@]}"; do
cat $item |
sed -n '/^alias [^-]/p' |
sed "s/\'//g" |
sed 's/\"//g' |
sed 's/\|/\\|/g' |
awk -v item=$(echo $item | awk -F/ '{name=$NF;split(name,splits,".");print splits[1]}') '
BEGIN {
print "### " item "\n"
}
{
split($0, a, "=");
split(a[1], b, " ");
print "- "b[2] ": `" a[2] "`"
}
END {
print ""
}' >>"$readme"
done
cat >>"$readme" <<EOM
## Completions
EOM
cmp_localtion="$SCRIPTS_ROOT/completion"
files=($(ls $cmp_localtion/*))
for item in "${files[@]}"; do
echo $item | awk -F/ '
{
split($NF, splits, ".");
print "- " splits[1]
}
END {
print ""
}' >> "$readme"
done
cat >>"$readme" <<EOM
## Functions
EOM
func_localtion="$SCRIPTS_ROOT/function"
files=($(ls $func_localtion/*))
for item in "${files[@]}"; do
cat $item | awk -v item=$(echo $item | awk -F/ '{name=$NF;split(name,splits,".");print splits[1]}') \
-F'(' '
BEGIN{
num=0;
print "### " item "\n"
}
/^function/ {
num+=1;
sub("function ", "", $1)
print num ". " $1
}
END {
print ""
}' >> "$readme"
done