aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2020-07-02 11:41:33 +0800
committerHsieh Chin Fan <typebrook@gmail.com>2020-07-02 11:41:36 +0800
commitad26de81576a733858042513a39d25fd89c7b085 (patch)
tree9cf33a9db78883f6cd0d93908baaf82ef834e586
parent8ba0d1fa017ae4344735cb21fcc46acb5255ab00 (diff)
Refine 'gist config'
- Update helper message - Remove checking for removed command - Print modified configuration after 'gist config'
-rwxr-xr-xgist9
1 files changed, 5 insertions, 4 deletions
diff --git a/gist b/gist
index 47a43bb..3f6b3ba 100755
--- a/gist
+++ b/gist
@@ -30,7 +30,8 @@
30# delete, D <INDEX>... [--force] Delete gists by given indices 30# delete, D <INDEX>... [--force] Delete gists by given indices
31# push, P <INDEX> Push changes by git (well, better to make commit by youself) 31# push, P <INDEX> Push changes by git (well, better to make commit by youself)
32# clean, C Clean local repos of removed gists 32# clean, C Clean local repos of removed gists
33# config, c [token|user|folder|auto_sync|EDITOR|action|protocol|show_untagged [value]] Do configuration 33# config, c Configure with editor, will show all valid keys
34# config, c <VALID_KEY> [value] Configure a single option. If no value is specified, apply default setting
34# user, u <USER> Get list of gists with a given Github user 35# user, u <USER> Get list of gists with a given Github user
35# github, G <INDEX> Export selected gist as a new Github repo 36# github, G <INDEX> Export selected gist as a new Github repo
36# help, h Show this help message 37# help, h Show this help message
@@ -195,7 +196,7 @@ _ask_token() {
195 196
196# Check configuration is fine with user setting 197# Check configuration is fine with user setting
197_validate_config() { 198_validate_config() {
198 [[ $1 =~ ^(c|config|h|help|u|user|update|version) ]] && return 0 199 [[ $1 =~ ^(c|config|h|help|u|user|update) ]] && return 0
199 if [[ -z $user ]]; then 200 if [[ -z $user ]]; then
200 echo 'Hi fellow! To access your gists, I need your Github username' 201 echo 'Hi fellow! To access your gists, I need your Github username'
201 echo "Also a personal token with scope which allows \"gist\"!" 202 echo "Also a personal token with scope which allows \"gist\"!"
@@ -215,7 +216,7 @@ _validate_config() {
215 216
216# Apply current configuration into config file 217# Apply current configuration into config file
217_reformat_config() { 218_reformat_config() {
218 local line_token=$(sed -ne '/^token=/{p;q}' $CONFIG); line_token=${line_token:-token=} 219 local line_token=$(sed -ne '/^token=/h; ${x;p}' $CONFIG); line_token=${line_token:-token=$token}
219 for key in ${VALID_CONFIGS[@]}; do 220 for key in ${VALID_CONFIGS[@]}; do
220 [[ $key == token ]] && echo $line_token && continue # Because format may like this: token=$(COMMAND-TO-GET-TOKEN), just leave it untouched 221 [[ $key == token ]] && echo $line_token && continue # Because format may like this: token=$(COMMAND-TO-GET-TOKEN), just leave it untouched
221 local value="${!key}"; local valid_values=${CONFIG_VALUES[$key]} 222 local value="${!key}"; local valid_values=${CONFIG_VALUES[$key]}
@@ -892,7 +893,7 @@ case "$1" in
892 _clean_repos ;; 893 _clean_repos ;;
893 config | c) 894 config | c)
894 shift 895 shift
895 _configure "$@" && { _apply_config && (_check_protocol &>/dev/null &); } ;; 896 _configure "$@" && _apply_config && sed -ne "/^$1=/p" $CONFIG && (_check_protocol &>/dev/null &) ;;
896 user | u) 897 user | u)
897 shift 898 shift
898 _query_user "$@" ;; 899 _query_user "$@" ;;