-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwb_gh
executable file
·201 lines (160 loc) · 4.3 KB
/
pwb_gh
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
enable $( enable_ate )
source $( ate_sources ate_exit_on_error )
source $( ate_sources ate_confirm_functions )
source $( ate_sources ate_get_index_with_key )
enable $( enable_pwb )
source $( pwb_sources pwb_exit_on_error )
source $( pwb_sources pwb_display_ate_table )
source $( pwb_sources pwb_print_head )
get_repos()
{
local table_name="$1"
ate get_row_size "$table_name" -v row_size
ate_exit_on_error
if [ "$row_size" -ne 4 ]; then
echo "Incorrect table row size."
exit
fi
local array_name
ate get_array_name "$table_name" -v array_name
ate_exit_on_error
local -n gt_array="$array_name"
local OIFS="$IFS"
local IFS=$'\t'
local -a cur
local -i el_count line_count=0
while read -r; do
(( ++line_count ))
IFS=$'\t' read -r -a cur <<< "$REPLY"
el_count="${#cur[*]}"
if [ "$el_count" -eq 4 ]; then
gt_array+=( "${cur[@]}" )
elif [ "$el_count" -eq 3 ]; then
# If missing description, add blank element to fill out record
gt_array+=( "${cur[0]}" "" "${cur[@]:1}" )
else
echo "at source line ${line_count}, the record has $el_count elements when it should have $row_size"
echo "$REPLY"
exit
fi
done < <( gh repo list -L 1000 )
ate index_rows "$table_name"
ate_exit_on_error
}
repo_size_names()
{
local rname="$1"
local -n rsn_return="$rname"
local tname="$2"
rsn_stepper()
{
local -n rs_row="$1"
local -n rs_max="$rname"
local val="${rs_row[0]##*/}"
local len="${#val}"
(( rs_max = len > rs_max ? len : rs_max ))
}
rs_return=0
ate walk_rows "$tname" rsn_stepper
}
repo_view_print_line()
{
local -i index="$1"
local tname="$2"
local -i char_limit="$3"
local -a row
ate get_row "$tname" "$index" -a row
ate_exit_on_error
row[0]="${row[0]##*/}"
local kind="${row[2]}"
local -i private=0
local -i forked=0
if [[ "$kind" =~ "private" ]]; then
private=1
printf $'\e[31;1m'
fi
if [[ "$kind" =~ "forked" ]]; then
forked=1
printf $'\e[43;1m'
fi
# shellcheck disable=SC2059
printf -v tline "$LINE_FORMAT" "${row[0]}" "${row[1]}"
pwb limit_print "$char_limit" "$tline"
printf $'\e[m'
}
repo_view_print_head()
{
local -i index="$1"
local tname="$2"
local -i char_limit="$3"
local pname="$5"
local -a row
ate get_row "$tname" "$index" -a row
ate_exit_on_error
local -a msg_lines=(
"${row[0]}"
"${row[3]}"
)
if [[ "${row[2]}" =~ private ]]; then
printf -v msg_lines[2] $'\e[31;1m%s\e[m' "${row[2]}"
else
msg_lines+=( "${row[2]}" )
fi
local -a desc_words
read -d "" -r -a desc_words <<< "${row[1]}"
local -i max_len=$(( char_limit < 60 ? char_limit : 60 ))
local -i word_len line_len
local curline
for word in "${desc_words[@]}"; do
line_len="${#curline}"
word_len="${#word}"
if (( line_len + word_len < max_len )); then
curline="${curline} ${word}"
else
msg_lines+=( "$curline" )
curline="$word"
fi
done
if [ "${#curline}" -gt 0 ]; then
msg_lines+=( "$curline" )
fi
pwb_print_head "$pname" msg_lines
}
repo_view_execute()
{
local keyp="$1"
local -i index="$2"
local dname="$3"
local pname="$4"
ate get_row "$dname" "$index"
local repo_name="${ATE_ARRAY[0]}"
if [[ "$keyp" == $'\cm' ]]; then
gh browse -R "$repo_name" &
fi
}
##########################
### Setup Global Table ###
##########################
declare repo_table
ate declare repo_table 4
ate_exit_on_error
get_repos repo_table
ate get_row_count repo_table -v row_count
ate_exit_on_error
declare -i MAX_NAME_LEN
repo_size_names MAX_NAME_LEN repo_table
declare LINE_FORMAT
printf -v LINE_FORMAT "%%-%ds %s" "$MAX_NAME_LEN"
##############################
### Setup and Start Viewer ###
##############################
declare repo_view
pwb declare repo_view repo_table "$row_count" repo_view_print_line \
-t repo_view_print_head \
-e repo_view_execute
pwb set_margins repo_view 8 2 2
pwb init
# pwb_display_ate_table repo_table
pwb start repo_view
pwb restore