aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-02-16 01:24:59 +0800
committertypebrook <typebrook@gmail.com>2020-02-16 01:24:59 +0800
commit189b99d83c4f5911f6e3ed58f58ca1d1ce385c75 (patch)
tree331b8db2acaca68024b42e1dec47fb3d9735bb3b
parent8872aba72bda92ad8cbbe1e62e4ceda5a4cf217b (diff)
update
-rwxr-xr-xscripts/gist30
1 files changed, 15 insertions, 15 deletions
diff --git a/scripts/gist b/scripts/gist
index a4033e1..cafe44a 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -8,7 +8,7 @@
8# Description: Manage your gists with git and Github API v3 8# Description: Manage your gists with git and Github API v3
9# Usage: gist [command] [<args>] 9# Usage: gist [command] [<args>]
10# 10#
11# [star | s] List your gists with format below, star for your starred gists: 11# [star | s] List your gists with format below, star for your starred gists:
12# [index_of_gist] [url] [file_num] [comment_num] [short description] 12# [index_of_gist] [url] [file_num] [comment_num] [short description]
13# fetch, f [star | s] Update the local list of your gists, star for your starred gists 13# fetch, f [star | s] Update the local list of your gists, star for your starred gists
14# <index_of_gist> [--no-action] Show the path of local gist repo and do custom actions 14# <index_of_gist> [--no-action] Show the path of local gist repo and do custom actions
@@ -124,7 +124,7 @@ update() {
124 if [[ $answer == [Yy] ]]; then 124 if [[ $answer == [Yy] ]]; then
125 cd ~ || { echo 'Update Failed'; exit 1; } 125 cd ~ || { echo 'Update Failed'; exit 1; }
126 if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Permissions Error: try running the update as sudo"; exit 1; } ; fi 126 if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Permissions Error: try running the update as sudo"; exit 1; } ; fi
127 echo -n "Downloading latest version of: $repositoryName." 127 echo -n "Downloading latest version of: $repositoryName."
128 # shellcheck disable=SC2015 128 # shellcheck disable=SC2015
129 git clone -q "https://github.com/$githubUserName/$repositoryName" && touch .BSnippetsHiddenFile || { echo "Failure!"; exit 1; } & 129 git clone -q "https://github.com/$githubUserName/$repositoryName" && touch .BSnippetsHiddenFile || { echo "Failure!"; exit 1; } &
130 while [ ! -f .BSnippetsHiddenFile ]; do { echo -n "."; sleep 2; };done 130 while [ ! -f .BSnippetsHiddenFile ]; do { echo -n "."; sleep 2; };done
@@ -160,7 +160,7 @@ _configure() {
160 [[ ! $2 =~ ^(true|false)$ ]] && return 1 160 [[ ! $2 =~ ^(true|false)$ ]] && return 1
161 fi 161 fi
162 local key=$1 && shift && local target=$key="'$*'" 162 local key=$1 && shift && local target=$key="'$*'"
163 else 163 else
164 echo "Not a valid key for configuration, use <$valid_keys> instead." 164 echo "Not a valid key for configuration, use <$valid_keys> instead."
165 return 1 165 return 1
166 fi 166 fi
@@ -226,16 +226,16 @@ _apply_config() {
226 226
227_check_repo_status() { 227_check_repo_status() {
228 if [[ ! -d $1 ]]; then 228 if [[ ! -d $1 ]]; then
229 if [[ $auto_sync == 'true' ]]; then 229 if [[ $auto_sync == 'true' ]]; then
230 echo "\e[32m[cloning]\e[0m"; 230 echo "\e[32m[cloning]\e[0m";
231 else 231 else
232 echo "\e[32m[Not cloned yet]\e[0m"; 232 echo "\e[32m[Not cloned yet]\e[0m";
233 fi 233 fi
234 else 234 else
235 cd "$1" || exit 235 cd "$1" || exit
236 if [[ -n $(git status --short) ]] &>/dev/null; then 236 if [[ -n $(git status --short) ]] &>/dev/null; then
237 echo "\e[36m[working]\e[0m" 237 echo "\e[36m[working]\e[0m"
238 else 238 else
239 [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && echo "\e[31m[outdated]\e[0m" 239 [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && echo "\e[31m[outdated]\e[0m"
240 [[ -n $(git cherry) ]] 2>/dev/null && echo "\e[31m[ahead]\e[0m" 240 [[ -n $(git cherry) ]] 2>/dev/null && echo "\e[31m[ahead]\e[0m"
241 fi 241 fi
@@ -245,7 +245,7 @@ _check_repo_status() {
245# Show the list of gist, but not updated time 245# Show the list of gist, but not updated time
246# show username for starred gist 246# show username for starred gist
247_show_list() { 247_show_list() {
248 if [[ ! -e $INDEX ]]; then 248 if [[ ! -e $INDEX ]]; then
249 echo 'No local file found for last update, please run command:' 249 echo 'No local file found for last update, please run command:'
250 echo ' gist update' 250 echo ' gist update'
251 return 0 251 return 0
@@ -299,7 +299,7 @@ for gist in raw:
299 print(gist["comments"], end=" ") 299 print(gist["comments"], end=" ")
300 print(gist["owner"]["login"], end=" ") 300 print(gist["owner"]["login"], end=" ")
301 print(gist["description"]) 301 print(gist["description"])
302 ' 302 '
303} 303}
304 304
305# TODO check if a user has no gist 305# TODO check if a user has no gist
@@ -316,7 +316,7 @@ _parse_response() {
316} 316}
317 317
318# TODO pagnation for more than 30 gists 318# TODO pagnation for more than 30 gists
319# TODO add files and date of a gist 319# TODO add files and date of a gist
320# get latest list of gists from Github API 320# get latest list of gists from Github API
321_fetch_gists() { 321_fetch_gists() {
322 echo "fetching $user's gists from $GITHUB_API..." 322 echo "fetching $user's gists from $GITHUB_API..."
@@ -438,7 +438,7 @@ print("updated_at:", raw["updated_at"])
438print("files:") 438print("files:")
439for file in raw["files"].keys(): 439for file in raw["files"].keys():
440 print(" ", file) 440 print(" ", file)
441 ' 441 '
442} 442}
443 443
444# equal to jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' 444# equal to jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}'
@@ -451,7 +451,7 @@ for comment in raw:
451 print("|", "created_at:", comment["created_at"]) 451 print("|", "created_at:", comment["created_at"])
452 print("|", "updated_at:", comment["updated_at"]) 452 print("|", "updated_at:", comment["updated_at"])
453 print("|", comment["body"]) 453 print("|", comment["body"])
454 ' 454 '
455} 455}
456 456
457_show_detail() { 457_show_detail() {
@@ -542,7 +542,7 @@ _edit_gist() {
542 542
543 echo -n 'Type new description: ' 543 echo -n 'Type new description: '
544 read -r DESC < /dev/tty 544 read -r DESC < /dev/tty
545 545
546 http_data=$(mktemp) 546 http_data=$(mktemp)
547 echo '{' \"description\": \"${$DESC//\"/\\\"}\" '}' > "$http_data" 547 echo '{' \"description\": \"${$DESC//\"/\\\"}\" '}' > "$http_data"
548 http_method PATCH "$http_data $GITHUB_API/gists/$GIST_ID" > /dev/null \ 548 http_method PATCH "$http_data $GITHUB_API/gists/$GIST_ID" > /dev/null \
@@ -596,7 +596,7 @@ case "$1" in
596 version) 596 version)
597 echo "Version $currentVersion" 597 echo "Version $currentVersion"
598 exit 0 ;; 598 exit 0 ;;
599 update) 599 update)
600 checkInternet || exit 1 600 checkInternet || exit 1
601 update 601 update
602 exit 0 602 exit 0