From aa770d7a8e2b02ccb5c27e2f40bec1a482497688 Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 4 Feb 2020 23:00:02 +0800 Subject: update --- scripts/gist | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/gist b/scripts/gist index e9e5130..4662c99 100755 --- a/scripts/gist +++ b/scripts/gist @@ -161,8 +161,6 @@ http_method() { } # Show the list of gist, but not updated time -# TODO a way to show files -# TODO show git status outdated _show_list() { if [[ ! -e $INDEX ]]; then echo 'No local file found for last update, please run command:' @@ -225,7 +223,7 @@ _parse_response() { done } -# TODO add author, files and date of a gist +# TODO add files and date of a gist # get latest list of gists from Github API _update() { echo "fetching $user's gists from $GITHUB_API..." -- cgit v1.2.3-70-g09d2 From 38f95948671f22d33bb4e34e66a456d0407ec051 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 5 Feb 2020 01:11:40 +0800 Subject: update --- scripts/gist | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/gist b/scripts/gist index 4662c99..d56b735 100755 --- a/scripts/gist +++ b/scripts/gist @@ -31,9 +31,8 @@ # TODO grep mode for description, file content # TODO push github.com (may need new token) -# TODO description for current directory # TODO unit test -# TODO test on mac and remote machine +# TODO test on bats, mac and remote machine # TODO completion # Shell configuration @@ -47,19 +46,20 @@ configuredClient="" # handle configuration cases _configure() { - local target="" [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 + + local target="" if [[ $1 == 'token' ]]; then [[ ${#2} -eq 40 ]] && target=$1=$2 \ || echo -e Invalid token format, it is not 40 chars '\n' > /dev/tty elif [[ $1 == 'auto_sync' ]]; then - [[ $2 == 'false' ]] && target=$1=$2 \ - || target=$1=true + [[ $2 == 'false' ]] && target=$1=$2 elif [[ $1 == 'folder' ]]; then - [[ -n "$2" ]] && target=$1=$2 \ - || target=$1=~/gist + [[ -n "$2" ]] && target=$1=$2 elif [[ $1 == 'user' ]]; then target=$1=$2 + elif [[ $1 == 'action' ]]; then + target=$1="$2" fi umask 0077 && touch $CONFIG -- cgit v1.2.3-70-g09d2 From 209a47a0273a153a091b0584722055af6d450707 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 5 Feb 2020 01:31:43 +0800 Subject: update --- scripts/gist | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/gist b/scripts/gist index d56b735..7d61e71 100755 --- a/scripts/gist +++ b/scripts/gist @@ -49,21 +49,18 @@ _configure() { [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 local target="" - if [[ $1 == 'token' ]]; then - [[ ${#2} -eq 40 ]] && target=$1=$2 \ - || echo -e Invalid token format, it is not 40 chars '\n' > /dev/tty + if [[ $1 == 'user' ]]; then + [[ -z $2 ]] && echo "Must specify username" >&2 && return 1 + elif [[ $1 == 'token' ]]; then + [[ ${#2} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 \ + && return 1 elif [[ $1 == 'auto_sync' ]]; then - [[ $2 == 'false' ]] && target=$1=$2 - elif [[ $1 == 'folder' ]]; then - [[ -n "$2" ]] && target=$1=$2 - elif [[ $1 == 'user' ]]; then - target=$1=$2 - elif [[ $1 == 'action' ]]; then - target=$1="$2" + [[ ! $2 =~ ^(true|false)$ ]] && return 1 fi + target=$1=$2 umask 0077 && touch $CONFIG - [[ "$target" =~ [^=]$ ]] && sed -i "/^$1=/ d" $CONFIG && echo $target >> $CONFIG + sed -i "/^$1=/ d" $CONFIG && [[ "$target" =~ [^=]$ ]] && echo $target >> $CONFIG cat $CONFIG } @@ -93,6 +90,7 @@ _ask_token() { _configure token $token } +# check configuration is fine with user setting _validate_config(){ source $CONFIG 2> /dev/null || true if [[ ! -e $CONFIG || -z $user ]]; then -- cgit v1.2.3-70-g09d2