From 166239fb10742bb32531732163bb00c43938a967 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 17 Jan 2020 12:04:18 +0800 Subject: update --- scripts/gist | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index 1e9cf8e..d69ed2e 100755 --- a/scripts/gist +++ b/scripts/gist @@ -63,11 +63,11 @@ starred=$folder/starred # Show the list of gist, but not updated time # TODO show git status outdated _show_list() { - list_file=$index - mark="" - [[ "$1" == "--star" ]] && list_file=$starred && mark="s" + list_files=$index + [[ "$1" == "--star" ]] && list_files=$starred + [[ "$1" == "--all" ]] && list_files="$index $starred" - cat $list_file |\ + cat $list_files |\ while read line_num link file_url_array file_num extra description; do repo=$folder/$(echo $link | sed 's#.*/##') @@ -78,7 +78,7 @@ _show_list() { # if there is a commit not yet push, show red message "ahead" [[ -n $(git cherry) ]] 2>/dev/null && extra="\e[31m[ahead]\e[0m" - echo -e $mark$line_num $link $file_num $extra $description + echo -e $line_num $link $file_num $extra $description done } @@ -87,14 +87,15 @@ _show_list() { _update() { list_file=$index route="users/$user/gists" - [[ "$1" == "--star" ]] && list_file=$starred && route="gists/starred" + mark="" + [[ "$1" == "--star" ]] && list_file=$starred && route="gists/starred" && mark="s" curl -s -H "$auth_header" $github_api/$route |\ jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' |\ tac | nl |\ while read line_num link file_url_array file_num comment_num description; do blob_code=$(echo $file_url_array | jq -r '.[]' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') - echo $line_num $link $blob_code $file_num $comment_num $(echo $description | cut -c -65) | tr -d '"' + echo $mark$line_num $link $blob_code $file_num $comment_num $(echo $description | cut -c -65) | tr -d '"' done > $list_file && \ _show_list $1 (_sync_repos $1 > /dev/null 2>&1 &) @@ -129,20 +130,19 @@ _sync_repos() { # TODO simplify _gist_id() { - list_file=$index - row_num=$1 - [[ "$1" =~ ^s ]] && list_file=$starred && row_num=$(echo $1 | tr -d 's') - cat $list_file | sed -n "$row_num"p | cut -d' ' -f2 | sed -E 's#.*/##' + cat $index $starred | sed -n "/^$1 / p" | cut -d' ' -f2 | sed -E 's#.*/##' } _goto_gist() { - gist_num=$(wc -l $index | cut -d' ' -f1) - if [[ ! "$1" =~ ^s?[0-9]+$ ]] || (( $1 > $gist_num )); then - _show_list | grep "$1" || echo Nothing Found + GIST_ID=$(_gist_id $1) + if [[ -z $GIST_ID ]]; then + echo Not a valid index: $1 + echo Use the index number in the first column instead: + echo + _show_list --all return 0 fi - GIST_ID=$(_gist_id $1) echo This gist is at $folder/$GIST_ID echo You can use the following command to jump to this directory: echo -e " \e[31m. gist $1\e[0m" -- cgit v1.2.3-70-g09d2