aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xgist18
1 files changed, 10 insertions, 8 deletions
diff --git a/gist b/gist
index 432ae62..7725f51 100755
--- a/gist
+++ b/gist
@@ -48,6 +48,8 @@ configuredClient=""
48GITHUB_API=https://api.github.com 48GITHUB_API=https://api.github.com
49CONFIG=~/.config/gist.conf; mkdir -p ~/.config 49CONFIG=~/.config/gist.conf; mkdir -p ~/.config
50 50
51INDEX_FORMAT=('index' 'url' 'blob_code' 'file_num' 'comment_num' 'author' 'created_at' 'updated_at' 'description')
52
51[[ -z $hint ]] && hint=true # default to show hint with list of gist 53[[ -z $hint ]] && hint=true # default to show hint with list of gist
52[[ -z $confirm ]] && confirm=true # default to confirm when deleting gists 54[[ -z $confirm ]] && confirm=true # default to confirm when deleting gists
53auto_sync=true # automatically clone the gist repo 55auto_sync=true # automatically clone the gist repo
@@ -265,14 +267,14 @@ _show_list() {
265 267
266 local prefix=$mark; [[ -z $prefix ]] && prefix=[^s] 268 local prefix=$mark; [[ -z $prefix ]] && prefix=[^s]
267 sed -Ene "/^$prefix/ p" $INDEX \ 269 sed -Ene "/^$prefix/ p" $INDEX \
268 | while read -r index link blob_code file_num comment_num author _ _ description; do 270 | while read -r ${INDEX_FORMAT[@]}; do
269 [[ $index =~ ^s ]] && local name=$author 271 [[ $index =~ ^s ]] && local name=$author
270 local repo; repo=$folder/${link##*/} 272 local repo; repo=$folder/${url##*/}
271 local extra; extra=$(_check_repo_status "$repo" "$blob_code") 273 local extra; extra=$(_check_repo_status "$repo" "$blob_code")
272 [[ -z $extra ]] && extra="$file_num $comment_num" 274 [[ -z $extra ]] && extra="$file_num $comment_num"
273 description=$(echo $description | sed -E -e 's/\[(.+)\]/\\e[33m[\1]\\e[0m/') 275 description=$(echo $description | sed -E -e 's/\[(.+)\]/\\e[33m[\1]\\e[0m/')
274 276
275 echo -e "$(printf "% 3s" "$index") $link $name $extra $description" \ 277 echo -e "$(printf "% 3s" "$index") $url $name $extra $description" \
276 | cut -c -"$(tput cols)" 278 | cut -c -"$(tput cols)"
277 done 279 done
278 280
@@ -337,11 +339,11 @@ for gist in raw:
337_parse_response() { 339_parse_response() {
338 _parse_gists \ 340 _parse_gists \
339 | tac | sed -e 's/, /,/g' | nl -s' ' \ 341 | tac | sed -e 's/, /,/g' | nl -s' ' \
340 | while read -r index link file_url_array public file_num comment_num author created_at updated_at description; do 342 | while read -r ${INDEX_FORMAT[@]:0:2} file_url_array public ${INDEX_FORMAT[@]:3:6}; do
341 local blob_code; blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -) 343 local blob_code; blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -)
342 local prefix=$mark; [[ $public == 'False' ]] && prefix=p 344 local prefix=$mark; [[ $public == 'False' ]] && prefix=p
343 [[ -n $1 ]] && local index=$1 345 [[ -n $1 ]] && local index=${prefix}${1} || local index=${prefix}${index}
344 echo "$prefix$index $link $blob_code $file_num $comment_num $author $created_at $updated_at $description" | tr -d '"' 346 eval "echo $(sed -Ee 's/([^ ]+)/$\1/g' <<<${INDEX_FORMAT[@]})"
345 done 347 done
346} 348}
347 349
@@ -377,8 +379,8 @@ _query_user() {
377 [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 379 [[ -z $result ]] && echo "Failed to query $1's gists" && return 1
378 380
379 echo "$result" \ 381 echo "$result" \
380 | while read -r index link blob_code file_num comment_num author _ _ description; do 382 | while read -r ${INDEX_FORMAT[@]}; do
381 echo "$link $author $file_num $comment_num $description" | cut -c -"$(tput cols)" 383 echo "$url $author $file_num $comment_num $description" | cut -c -"$(tput cols)"
382 done 384 done
383} 385}
384 386