diff options
author | typebrook <typebrook@gmail.com> | 2020-01-17 12:04:18 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-01-17 12:04:18 +0800 |
commit | 166239fb10742bb32531732163bb00c43938a967 (patch) | |
tree | 9616074b6e08156a869e5d05aaa7411c2894ee55 /scripts/gist | |
parent | 9809c55f5052cfc361c66e22ae959c54fc95b1f9 (diff) |
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-x | scripts/gist | 30 |
1 files changed, 15 insertions, 15 deletions
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 | |||
63 | # Show the list of gist, but not updated time | 63 | # Show the list of gist, but not updated time |
64 | # TODO show git status outdated | 64 | # TODO show git status outdated |
65 | _show_list() { | 65 | _show_list() { |
66 | list_file=$index | 66 | list_files=$index |
67 | mark="" | 67 | [[ "$1" == "--star" ]] && list_files=$starred |
68 | [[ "$1" == "--star" ]] && list_file=$starred && mark="s" | 68 | [[ "$1" == "--all" ]] && list_files="$index $starred" |
69 | 69 | ||
70 | cat $list_file |\ | 70 | cat $list_files |\ |
71 | while read line_num link file_url_array file_num extra description; do | 71 | while read line_num link file_url_array file_num extra description; do |
72 | repo=$folder/$(echo $link | sed 's#.*/##') | 72 | repo=$folder/$(echo $link | sed 's#.*/##') |
73 | 73 | ||
@@ -78,7 +78,7 @@ _show_list() { | |||
78 | # if there is a commit not yet push, show red message "ahead" | 78 | # if there is a commit not yet push, show red message "ahead" |
79 | [[ -n $(git cherry) ]] 2>/dev/null && extra="\e[31m[ahead]\e[0m" | 79 | [[ -n $(git cherry) ]] 2>/dev/null && extra="\e[31m[ahead]\e[0m" |
80 | 80 | ||
81 | echo -e $mark$line_num $link $file_num $extra $description | 81 | echo -e $line_num $link $file_num $extra $description |
82 | done | 82 | done |
83 | } | 83 | } |
84 | 84 | ||
@@ -87,14 +87,15 @@ _show_list() { | |||
87 | _update() { | 87 | _update() { |
88 | list_file=$index | 88 | list_file=$index |
89 | route="users/$user/gists" | 89 | route="users/$user/gists" |
90 | [[ "$1" == "--star" ]] && list_file=$starred && route="gists/starred" | 90 | mark="" |
91 | [[ "$1" == "--star" ]] && list_file=$starred && route="gists/starred" && mark="s" | ||
91 | 92 | ||
92 | curl -s -H "$auth_header" $github_api/$route |\ | 93 | curl -s -H "$auth_header" $github_api/$route |\ |
93 | jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' |\ | 94 | jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' |\ |
94 | tac | nl |\ | 95 | tac | nl |\ |
95 | while read line_num link file_url_array file_num comment_num description; do | 96 | while read line_num link file_url_array file_num comment_num description; do |
96 | blob_code=$(echo $file_url_array | jq -r '.[]' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') | 97 | blob_code=$(echo $file_url_array | jq -r '.[]' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') |
97 | echo $line_num $link $blob_code $file_num $comment_num $(echo $description | cut -c -65) | tr -d '"' | 98 | echo $mark$line_num $link $blob_code $file_num $comment_num $(echo $description | cut -c -65) | tr -d '"' |
98 | done > $list_file && \ | 99 | done > $list_file && \ |
99 | _show_list $1 | 100 | _show_list $1 |
100 | (_sync_repos $1 > /dev/null 2>&1 &) | 101 | (_sync_repos $1 > /dev/null 2>&1 &) |
@@ -129,20 +130,19 @@ _sync_repos() { | |||
129 | 130 | ||
130 | # TODO simplify | 131 | # TODO simplify |
131 | _gist_id() { | 132 | _gist_id() { |
132 | list_file=$index | 133 | cat $index $starred | sed -n "/^$1 / p" | cut -d' ' -f2 | sed -E 's#.*/##' |
133 | row_num=$1 | ||
134 | [[ "$1" =~ ^s ]] && list_file=$starred && row_num=$(echo $1 | tr -d 's') | ||
135 | cat $list_file | sed -n "$row_num"p | cut -d' ' -f2 | sed -E 's#.*/##' | ||
136 | } | 134 | } |
137 | 135 | ||
138 | _goto_gist() { | 136 | _goto_gist() { |
139 | gist_num=$(wc -l $index | cut -d' ' -f1) | 137 | GIST_ID=$(_gist_id $1) |
140 | if [[ ! "$1" =~ ^s?[0-9]+$ ]] || (( $1 > $gist_num )); then | 138 | if [[ -z $GIST_ID ]]; then |
141 | _show_list | grep "$1" || echo Nothing Found | 139 | echo Not a valid index: $1 |
140 | echo Use the index number in the first column instead: | ||
141 | echo | ||
142 | _show_list --all | ||
142 | return 0 | 143 | return 0 |
143 | fi | 144 | fi |
144 | 145 | ||
145 | GIST_ID=$(_gist_id $1) | ||
146 | echo This gist is at $folder/$GIST_ID | 146 | echo This gist is at $folder/$GIST_ID |
147 | echo You can use the following command to jump to this directory: | 147 | echo You can use the following command to jump to this directory: |
148 | echo -e " \e[31m. gist $1\e[0m" | 148 | echo -e " \e[31m. gist $1\e[0m" |