-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrubs
executable file
·124 lines (105 loc) · 3.53 KB
/
scrubs
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
#!/bin/sh
files() {
find . -regextype posix-egrep -regex ".*\.(cpp|c)" -print0
}
get_todos() {
if [ -z "$1" ]; then
files | xargs -0 grep -HPzo '/\*\*\sTODO(\n\s*\*\N*)*\n\s*\*/\n'
else
files | xargs -0 grep -HPzo "/\*\*\sTODO(\n\s*\*\N*)*\n\s*\*\s*@category\s*\N*$1\N*(\n\s*\*\N*)*\n\s*\*/\n"
fi
}
todos() {
hline=$(printf "%0.s─" $(seq $(($(tput cols) - 2))))
hbordertop=$(printf "┌%s┐" "$hline")
hborderbot=$(printf "└%s┘" "$hline")
titleline=$(printf "%s" "$hline")
newline
printf "%b" "$(get_todos "$1" | \
sed -e "s/^.*\/\*\* TODO/\\\\033[2;3;39m${hbordertop}\\\\033[0m\\\\n &\\\\033[2;3;39m ${titleline}\\\\033[0m/g" | \
sed -e 's/^\s*\*/\*/g' -e 's/\/\*\* TODO/\n/g' | \
sed -e "s/^\*\//\\\\033[2;3;39m$hborderbot\\\\033[0m\\\\n/g" | \
sed -e 's/^\*/ /g' | \
sed -E 's/@category (.*)/\\033[34m\1\\033[0m/g' | \
sed -E 's/@description/\\033[2mdescription\\033[0m/g')\n"
}
get_docs() {
if [ -z "$1" ]; then
files | xargs -0 grep -HPzo '/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*/\n'
else
if [ -z "$2" ]; then
files | xargs -0 grep -HPzo "/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*\s*@type\s*\N*$1\N*(\n\s*\*\N*)*\n\s*\*/\n"
else
files | xargs -0 grep -HPzo "/\*\*\sDOC(\n\s*\*\N*)*\n\s*\*\s*@type\s*\N*$1\N*\n\s*\*\s*@name\s*\N*$2\N*(\n\s*\*\N*)*\n\s*\*/\n"
fi
fi
}
doc() {
hline=$(printf "%0.s─" $(seq $(($(tput cols) - 2))))
hbordertop=$(printf "┌%s┐" "$hline")
hborderbot=$(printf "└%s┘" "$hline")
titleline=$(printf "%s" "$hline")
newline
output=$(get_docs "$1" "$2" | \
sed -e "s/^.*\/\*\* DOC/\\\\033[2;3;39m${hbordertop}\\\\033[0m\\\\n &\\\\033[2;3;39m ${titleline}\\\\033[0m/g" | \
sed -e 's/^\s*\*/\*/g' -e 's/\/\*\* DOC/\n/g' | \
sed -e "s/^\*\//\\\\033[2;3;39m$hborderbot\\\\033[0m\\\\n/g" | \
sed -e 's/^\*/ /g' | \
sed -E 's/@type (.*)/\\033[32m\1\\033[0m/g' | \
sed -E 's/@name (.*)/\\033[34m\1\\033[0m/g' | \
sed -E 's/@param (.*)/\\033[2mparam\\033[0m \\033[33m\1\\033[0m/g' | \
sed -E 's/@inherit (.*)/\\033[2minherit from\\033[0m \\033[33m\1\\033[0m/g' | \
sed -E 's/@return (.*)/\\033[2mreturn\\033[0m \\033[33m\1\\033[0m/g' | \
sed -E 's/@description/\\033[2mdescription\\033[0m/g')
if [ "$(printf "%s" "$output" | wc -l)" -eq 0 ]; then
printf "%s\n" "There is no documentation for '$1' '$2'"
newline
else
printf "%b\n" "${output}"
fi
}
search() {
docs=$(get_docs "" "")
list=$(echo "$docs" | grep -Pzo '@type\N*\n\s*\*\s*@name\N*\n' | sed -Ez 's/@type\s*(.*)\n\s*\*\s*@name\s*(.*)\n/\\033[32m\1\\033[0m \\033[34m\2\\033[0m\n/g')
selected=$(printf "%b" "${list}" | fzf --ansi --preview "scrubs doc \"\$(echo {} | awk '{ print \$1 }')\" \"\$(echo {} | awk '{ print \$2 }')\" | less -R")
while [ -n "$selected" ]; do
doc "$selected" | less -R
selected=$(printf "%b" "${list}" | fzf --ansi --preview 'scrubs doc {} | less -R')
done
}
title() {
printf '\033[34m'
printf "%s" "$1"
printf '\033[2;3;39m - '
printf "%s" "$2"
printf '\033[0m\n'
}
newline() {
printf '\n'
}
comment() {
printf '\033[2;3;39m'
printf "%s", "$1"
printf '\033[0m'
}
help() {
newline
title "scrubs" "Let's Prepare The Operation"
newline
comment "Overview"
newline
newline
printf " todo [category] - list todos [in this category]\n"
printf " doc [type] [name] - list documentation for specific type\n"
printf " search - browse through the docs (fzf needed)\n"
newline
comment "To report bugs, or if you need help send a message to <nathan@reinerweb.ch> or see github.com/NPScript."
newline
newline
}
case "$1" in
todo) todos "$2";;
doc) doc "$2" "$3";;
search) search;;
*) help;;
esac