From 183fca611aa678b7af7ee447f8ab462323dbe7e4 Mon Sep 17 00:00:00 2001 From: typebrook Date: Sat, 1 Feb 2020 11:36:56 +0800 Subject: update --- scripts/gist | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/scripts/gist b/scripts/gist index d55516c..16102e8 100755 --- a/scripts/gist +++ b/scripts/gist @@ -133,15 +133,14 @@ _apply_config() { fi source $CONFIG + + [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder + INDEX=$folder/index + AUTH_HEADER="Authorization: token $token" } _apply_config "$@" || exit 1 -AUTH_HEADER="Authorization: token $token" - -[[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder -INDEX=$folder/index - ## This function determines which http get tool the system has installed and returns an error if there isnt one getConfiguredClient() { @@ -291,21 +290,21 @@ _gist_id() { } _goto_gist() { - _gist_id $1 + _gist_id $1 || return 1 if [[ ! -d $folder/$GIST_ID ]]; then echo 'Cloning gist as repo...' git clone git@github.com:$GIST_ID.git $folder/$GIST_ID - if [[ "$?" -ne 0 ]]; then - echo 'Repo is cloned' > /dev/tty + + if [[ $? -eq 0 ]]; then + echo 'Repo is cloned' > /dev/tty else - echo 'Failed to clone the gist' > /dev/tty + echo 'Failed to clone the gist' > /dev/tty + return 1 fi fi echo $folder/$GIST_ID - cd $folder/$GIST_ID && ls - #tig --all 2> /dev/null || true } _delete_gist() { @@ -402,16 +401,17 @@ _create_gist() { [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty local index=$(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) - echo 'Creating a new gist' + echo 'Creating a new gist...' for file in $files; do echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \ | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ | curl -s -H "$AUTH_HEADER" --data @- $GITHUB_API/gists \ + | tee jojo \ | sed '1 s/^/[/; $ s/$/]/' \ | _parse_response $index >> $INDEX - if [[ "$?" -ne 0 ]]; then + if [[ $? -eq 0 ]]; then echo 'Gist is created' _show_list | tail -1 else -- cgit v1.2.3-70-g09d2