-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.sh
69 lines (59 loc) · 1.16 KB
/
util.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
#!/usr/bin/env bash
_showHelp() {
indent=false
helpText="
usage: $(basename "${0}") -h [QUERY...]
options:
-h, --help show help
"
# unindenting the message below,
# so i don't have to format it above
while IFS="" read -r line; do
# ignore blank lines
charsOnly="${line/ //}"
if [[ ${#charsOnly} -eq 0 ]]; then
echo
else
# set indent to first non empty line
if [[ ${indent} == false ]]; then
indent=$(
# get number of leading spaces
echo "${line}" | awk -F'[^ ]' '{print length($1)}'
)
fi
# formatted
echo "${line}" | cut -c "$((indent + 1))-"
fi
done < <(echo "${helpText}") | bat -pp -l help
}
_parseArgs() {
while [[ ${#*} -gt 0 ]]; do
case ${1} in
-h | --help)
_showHelp
exit 0
;;
*)
shift
;;
esac
done
}
_getInput() {
q="${*}"
while [[ ${#q} -eq 0 ]]; do
read -erp "search: " q
done
echo "${q}"
}
_searchRepos() {
gh search repos \
--sort "stars" \
--limit 100 \
--json "fullName" \
--jq '.[].fullName' \
"${@}"
}
_viewReadme() {
gh repo view "${@}" | glow -p
}