From 42a220d70b28141e0ba39f86a3b1d236d2545849 Mon Sep 17 00:00:00 2001 From: typebrook Date: Mon, 20 Jan 2020 15:01:38 +0800 Subject: update --- gist | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/gist b/gist index 55c9ab8..ad08016 100755 --- a/gist +++ b/gist @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Author: Hsieh Chin Fan (typebrook) +# Author: Hsieh Chin Fan (typebrook) # License: MIT # https://gist.github.com/typebrook/b0d2e7e67aa50298fdf8111ae7466b56 # @@ -10,8 +10,8 @@ # # Use the following commands to manage your gists: # -# * update your gists list with Github API -# gist [update | u] +# * update the local list of your gists, star for your starred gists +# gist (update | u) [star | s] # # * list your gists with format: [number] [url] [file_num] [comment_num] [short description] # gist @@ -191,16 +191,6 @@ _show_detail() { jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' } -_new_file() { - [[ -t 0 ]] && echo "Type a gist. to cancel, when done" > /dev/tty - tmp_file=$(mktemp) - cat > $tmp_file - echo - [[ -z "$1" ]] && echo -en '\nType file name: ' > /dev/tty && read filename - mv $tmp_file /tmp/$filename - echo /tmp/$filename -} - _set_gist() { while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in -d | --desc) @@ -215,12 +205,22 @@ _set_gist() { files=$@ } +_new_file() { + [[ -t 0 ]] && echo "Type a gist. to cancel, when done" > /dev/tty + tmp_file=$(mktemp) + cat > $tmp_file + echo -e '\n' > /dev/tty + [[ -z "$1" ]] && echo -n 'Type file name: ' > /dev/tty && read filename + mv $tmp_file /tmp/$filename + echo /tmp/$filename +} + # create a new gist with files # FIXME error handling if gist is not created _create_gist() { _set_gist "$@" [[ -z $files ]] && files=$(_new_file $filename) - [[ -z $description ]] && echo -en '\nDescription: ' && read description + [[ -z $description ]] && echo -n 'Type description: ' && read description for file in $files; do FILE=$(basename $file) @@ -235,8 +235,7 @@ _create_gist() { sed '1 s/^/[/; $ s/$/]/' |\ _parse_response |\ sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index && \ - echo Gist created - echo + echo -e '\nGist created' _show_list $index | tail -1 } @@ -259,7 +258,7 @@ case "$1" in "") _show_list $index ;; star | s) - _show_list $starred ;; + _show_list $starred ;; update | u) _update "$2" ;; new | n) -- cgit v1.2.3-70-g09d2