From fd2b6af2ea01461cdba60cd97aa9f1ee805fd157 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 31 Jan 2020 14:11:59 +0800 Subject: update --- scripts/gist | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index f33f83f..58c949f 100755 --- a/scripts/gist +++ b/scripts/gist @@ -63,8 +63,7 @@ set -eo pipefail [ "$TRACE" ] && set -x GITHUB_API=https://api.github.com -CONFIG=~/.config/gistrc -mkdir -p ~/.config && umask 0077 +CONFIG=~/.config/gist.conf; mkdir -p ~/.config configuredClient="" _config_cases() { @@ -86,7 +85,7 @@ _configure() { [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 target=$(_config_cases "$@") - touch $CONFIG + umask 0077 && touch $CONFIG [[ "$target" =~ [^=]$ ]] && sed -i "/^$1=/ d" $CONFIG && echo $target >> $CONFIG cat $CONFIG } @@ -114,10 +113,11 @@ _ask_token() { } _apply_config() { - source $CONFIG + source $CONFIG 2> /dev/null || true if [[ ! -e $CONFIG ]] || [[ -z $user ]]; then - echo -n 'Hi fellow! To access your gists, I need your Github username, ' - echo -n "also a personal token with scope which allows "gist"!'" + echo 'Hi fellow! To access your gists, I need your Github username' + echo "Also a personal token with scope which allows "gist"!'" + echo _ask_username _ask_token elif [[ -z $token ]] && [[ $1 =~ ^(n|new|e|edit|D|delete)$ ]]; then @@ -174,7 +174,7 @@ _show_list() { return 0 fi cat $1 \ - | while read line_num link file_url_array file_num extra description; do + | while read index link blob_code file_num extra description; do local repo=$folder/$(echo $link | sed 's#.*/##') local occupy=0 @@ -185,7 +185,7 @@ _show_list() { # if there is a commit not yet push, show red message "ahead" [[ -n $(cd $repo && git cherry) ]] 2>/dev/null && extra="\e[31m[ahead]\e[0m" && occupy=7 - echo -e $line_num $link $file_num $extra $(echo $description | cut -c -$(( 60 -$occupy -1 )) ) + echo -e $index $link $file_num $extra $(echo $description | cut -c -$(( 60 -$occupy -1 )) ) done } @@ -202,6 +202,7 @@ _handle_gists() { for gist in raw: print(gist["html_url"], end=" ") print([file["raw_url"] for file in gist["files"].values()], end=" ") + print(gist["public"], end=" ") print(len(gist["files"]), end=" ") print(gist["comments"], end=" ") print(gist["description"]) @@ -211,10 +212,11 @@ for gist in raw: # TODO check if a user create a very first gist _parse_response() { AccessJsonElement "$(_handle_gists)" \ - | tac | sed 's/, /,/g'\ - | while read link file_url_array file_num comment_num description; do + | tac | sed 's/, /,/g' | nl -s' ' \ + | while read index link file_url_array public file_num comment_num description; do local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') - echo $link $blob_code $file_num $comment_num $description | tr -d '"' + [[ $public == 'False' ]] && mark=p + echo $mark$index $link $blob_code $file_num $comment_num $description | tr -d '"' done } @@ -227,8 +229,8 @@ _update() { local mark="" [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" && mark="s" - httpGet $GITHUB_API/$route \ - | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \ + curl -H "$auth_header" $GITHUB_API/$route \ + | _parse_response | sed -E "s/^ */$mark/" > $list_file \ && _show_list $list_file \ || echo Fail to update gists -- cgit v1.2.3-70-g09d2