-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.sh
executable file
·40 lines (30 loc) · 964 Bytes
/
index.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
#!/usr/bin/env bash
selfdir="$(dirname "${0}")"
source "${selfdir}/ui.sh"
source "${selfdir}/util.sh"
_mainLoop() {
clear
outfile=$(mktemp) # used to communicate between functions
q=$(_getInput "${@}")
[[ ${#q} -gt 0 ]] &&
echo "searching for ${q}" &&
declare -a searchResults="($(_searchRepos "${q}"))"
[[ ${#searchResults[@]} -eq 0 ]] &&
echo "no results" &&
_mainLoop
while true; do
_viewMultiplePages "${searchResults[@]}" -o "${outfile}" &&
selection=$(cat "${outfile}")
if [[ "${#selection}" -gt 0 ]]; then
branchName=$(gh api "repos/${selection}" | jq -r '.default_branch')
treeJSON=$(gh api "repos/${selection}/git/trees/${branchName}")
_viewReadme "${selection}" && # view README.md
_viewFileTree "${treeJSON}" || # preview files in repo
_mainLoop # handle empty repos
else
_mainLoop
fi
done
}
_parseArgs "${@}"
_mainLoop "${@}"