diff options
| author | typebrook <typebrook@gmail.com> | 2020-01-31 11:37:23 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-01-31 11:37:23 +0800 |
| commit | 3370ee794c2d172a1647fe57caea2669b567c046 (patch) | |
| tree | c868b33dc843b38c5cb09f660353fefb102043fb /scripts | |
| parent | aeb9e4f968c38117f10d9997e6dff5e5d6e75411 (diff) | |
update
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gist | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist index 34d1351..bd48566 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -63,7 +63,7 @@ set -eo pipefail | |||
| 63 | [ "$TRACE" ] && set -x | 63 | [ "$TRACE" ] && set -x |
| 64 | 64 | ||
| 65 | GITHUB_API=https://api.github.com | 65 | GITHUB_API=https://api.github.com |
| 66 | config=~/.config/gistrc | 66 | CONFIG=~/.config/gistrc |
| 67 | mkdir -p ~/.config && umask 0077 | 67 | mkdir -p ~/.config && umask 0077 |
| 68 | 68 | ||
| 69 | _config_cases() { | 69 | _config_cases() { |
| @@ -82,12 +82,12 @@ _config_cases() { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | _configure() { | 84 | _configure() { |
| 85 | [[ -z "$@" ]] && (${EDITOR:-vi} $config) && return 0 | 85 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 |
| 86 | target=$(_config_cases "$@") | 86 | target=$(_config_cases "$@") |
| 87 | 87 | ||
| 88 | touch $config | 88 | touch $CONFIG |
| 89 | [[ "$target" =~ [^=]$ ]] && sed -i "/^$1=/ d" $config && echo $target >> $config | 89 | [[ "$target" =~ [^=]$ ]] && sed -i "/^$1=/ d" $CONFIG && echo $target >> $CONFIG |
| 90 | cat $config | 90 | cat $CONFIG |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | _ask_username() { | 93 | _ask_username() { |
| @@ -113,8 +113,8 @@ _ask_token() { | |||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | _apply_config() { | 115 | _apply_config() { |
| 116 | source $config | 116 | source $CONFIG |
| 117 | if [[ ! -e $config ]] || [[ -z $user ]]; then | 117 | if [[ ! -e $CONFIG ]] || [[ -z $user ]]; then |
| 118 | echo 'Hi fellow! To access your gists, I need your Github username, also a personal token with scope which allows "gist"!' | 118 | echo 'Hi fellow! To access your gists, I need your Github username, also a personal token with scope which allows "gist"!' |
| 119 | _ask_username | 119 | _ask_username |
| 120 | _ask_token | 120 | _ask_token |
| @@ -122,7 +122,7 @@ _apply_config() { | |||
| 122 | _ask_token | 122 | _ask_token |
| 123 | fi | 123 | fi |
| 124 | 124 | ||
| 125 | source $config | 125 | source $CONFIG |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | _apply_config "$@" | 128 | _apply_config "$@" |