diff options
Diffstat (limited to 'scripts/gist')
-rwxr-xr-x | scripts/gist | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/scripts/gist b/scripts/gist index 2ac7fd7..1222e82 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -15,7 +15,7 @@ | |||
15 | # new, n [-d | --desc <description>] <files>... create a new gist with files | 15 | # new, n [-d | --desc <description>] <files>... create a new gist with files |
16 | # new, n [-d | --desc <description>] [-f | --file <file_name>] create a new gist from STDIN | 16 | # new, n [-d | --desc <description>] [-f | --file <file_name>] create a new gist from STDIN |
17 | # detail, d <index_of_gist> show the detail of a gist | 17 | # detail, d <index_of_gist> show the detail of a gist |
18 | # edit, e <index_of_gist> edit a gist description | 18 | # edit, e <index_of_gist> edit a gist's description |
19 | # delete, D <index_of_gist>... delete a gist | 19 | # delete, D <index_of_gist>... delete a gist |
20 | # clean, C clean removed gists in local | 20 | # clean, C clean removed gists in local |
21 | # config, c [token | user | folder | auto_sync | EDITOR | action [value] ] do configuration | 21 | # config, c [token | user | folder | auto_sync | EDITOR | action [value] ] do configuration |
@@ -49,15 +49,17 @@ _configure() { | |||
49 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 | 49 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 |
50 | 50 | ||
51 | local target="" | 51 | local target="" |
52 | if [[ $1 == 'user' ]]; then | 52 | if [[ $1 =~ ^(user|token|folder|auto_sync|EDITOR|action)$ ]]; then |
53 | [[ -z $2 ]] && echo "Must specify username" >&2 && return 1 | 53 | if [[ $1 == 'user' ]]; then |
54 | elif [[ $1 == 'token' ]]; then | 54 | [[ -z $2 ]] && echo "Must specify username" >&2 && return 1 |
55 | [[ ${#2} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 \ | 55 | elif [[ $1 == 'token' ]]; then |
56 | && return 1 | 56 | [[ ${#2} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 \ |
57 | elif [[ $1 == 'auto_sync' ]]; then | 57 | && return 1 |
58 | [[ ! $2 =~ ^(true|false)$ ]] && return 1 | 58 | elif [[ $1 == 'auto_sync' ]]; then |
59 | [[ ! $2 =~ ^(true|false)$ ]] && return 1 | ||
60 | fi | ||
61 | target=$1=$2 | ||
59 | fi | 62 | fi |
60 | target=$1=$2 | ||
61 | 63 | ||
62 | umask 0077 && touch $CONFIG | 64 | umask 0077 && touch $CONFIG |
63 | sed -i "/^$1=/ d" $CONFIG && [[ "$target" =~ [^=]$ ]] && echo $target >> $CONFIG | 65 | sed -i "/^$1=/ d" $CONFIG && [[ "$target" =~ [^=]$ ]] && echo $target >> $CONFIG |