aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2020-06-30 18:39:16 +0800
committerHsieh Chin Fan <typebrook@gmail.com>2020-06-30 18:46:46 +0800
commit2b75c047ee1b1efcab93af41fb2c84600e3770a8 (patch)
tree0e527ab50d5fb13c1b449c4bcec2a8e4012ff932
parenta7d7878b3ce54163afdd28a1257e4bd9252d8b0b (diff)
parentb108934e8ee4875fc697712eb30d21ed4301f92b (diff)
Merge branch 'config'
-rwxr-xr-xgist23
1 files changed, 17 insertions, 6 deletions
diff --git a/gist b/gist
index 6077ebb..0b5dee4 100755
--- a/gist
+++ b/gist
@@ -48,7 +48,6 @@
48# Since now a gist is a local cloned repo 48# Since now a gist is a local cloned repo
49# It is your business to do git commit and git push 49# It is your business to do git commit and git push
50 50
51# TODO user friendly config file
52# TODO change gist from public to private or reverse versa 51# TODO change gist from public to private or reverse versa
53# TODO feature to exclude tag-value or grep-string 52# TODO feature to exclude tag-value or grep-string
54# TODO Save HEADER with wget and httpie 53# TODO Save HEADER with wget and httpie
@@ -63,6 +62,7 @@ CONFIG=~/.config/gist.conf; mkdir -p ~/.config
63per_page=100 62per_page=100
64 63
65INDEX_FORMAT=('index' 'public' 'gist_id' 'tags_string' 'blob_code' 'file_array' 'file_num' 'comment_num' 'author' 'created_at' 'updated_at' 'description') 64INDEX_FORMAT=('index' 'public' 'gist_id' 'tags_string' 'blob_code' 'file_array' 'file_num' 'comment_num' 'author' 'created_at' 'updated_at' 'description')
65VALID_CONFIGS=('user=' 'token=' 'folder=' 'auto_sync=true|false' 'action=' 'EDITOR=' 'protocol=https|ssh' 'show_untagged=true|false')
66TAG_CHAR='-_[:alnum:]' 66TAG_CHAR='-_[:alnum:]'
67if [[ ! -t 0 ]]; then 67if [[ ! -t 0 ]]; then
68 INPUT=$(cat) 68 INPUT=$(cat)
@@ -150,11 +150,10 @@ _process_json() {
150_configure() { 150_configure() {
151 [[ $# == 0 ]] && (${EDITOR:-vi} "$CONFIG") && return 0 151 [[ $# == 0 ]] && (${EDITOR:-vi} "$CONFIG") && return 0
152 152
153 local valid_keys='user|token|folder|auto_sync|EDITOR|action|protocol|show_untagged' 153 local key=$1; local value="$2"; local keys=${VALID_CONFIGS[@]%=*}
154 local key=$1; local value="$2"
155 154
156 [[ ! $key =~ ^($valid_keys)$ ]] \ 155 [[ ! " ${keys} " =~ " ${key} " ]] \
157 && echo "Not a valid key for configuration, use <$valid_keys> instead." \ 156 && echo "Not a valid key for configuration, use <${keys// /|}> instead." \
158 && return 1 157 && return 1
159 158
160 case $key in 159 case $key in
@@ -203,8 +202,20 @@ _ask_token() {
203 202
204# Check configuration is fine with user setting 203# Check configuration is fine with user setting
205_validate_config() { 204_validate_config() {
206 # shellcheck source=/dev/null
207 source "$CONFIG" 2> /dev/null 205 source "$CONFIG" 2> /dev/null
206 sed -i -Ee '/^(user|token)=/!d' "$CONFIG"
207 for pair in "${VALID_CONFIGS[@]}"; do
208 key=${pair%=*}; [[ $key =~ ^(user|token)$ ]] && continue
209 value="${!key}"
210 values=${pair#*=}
211 if [[ -n $value && $value =~ ($values) ]]; then
212 echo -n $key="'$value'"
213 else
214 echo -n ${pair%|*}
215 fi
216 echo -e "${values:+\t\t# Valid: $values}"
217 done >>"$CONFIG" && source "$CONFIG"
218
208 [[ $1 =~ ^(c|config|h|help|u|user|update|version) ]] && return 0 219 [[ $1 =~ ^(c|config|h|help|u|user|update|version) ]] && return 0
209 if [[ -z $user ]]; then 220 if [[ -z $user ]]; then
210 echo 'Hi fellow! To access your gists, I need your Github username' 221 echo 'Hi fellow! To access your gists, I need your Github username'