diff options
| author | typebrook <typebrook@gmail.com> | 2020-04-13 14:16:29 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-04-13 14:16:33 +0800 |
| commit | 0938ab431a001fced7b6a6ecace89a08ae0e3398 (patch) | |
| tree | 9ee485b967d1e7603044de97d36f2a38df68c3c4 | |
| parent | b3bf0e8a01e9ba24b71592823b12be6f0cd51516 (diff) | |
Make Command Substitution works with configuration
| -rwxr-xr-x | gist | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -176,19 +176,21 @@ _configure() { | |||
| 176 | if [[ $key == 'user' ]]; then | 176 | if [[ $key == 'user' ]]; then |
| 177 | [[ -z $value ]] && echo 'Must specify username' >&2 && return 1 | 177 | [[ -z $value ]] && echo 'Must specify username' >&2 && return 1 |
| 178 | elif [[ $key == 'token' ]]; then | 178 | elif [[ $key == 'token' ]]; then |
| 179 | [[ ${#value} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 && return 1 | 179 | [[ ${#value} -ne 40 && ! $value =~ ^(\$|\`) ]] && echo 'Invalid token format, it is not 40 chars' >&2 && return 1 |
| 180 | elif [[ $key =~ ^(auto_sync|show_untagged)$ ]]; then | 180 | elif [[ $key =~ ^(auto_sync|show_untagged)$ ]]; then |
| 181 | [[ ! $value =~ ^(true|false)$ ]] && echo "$key must be either true or false" >&2 && return 1 | 181 | [[ ! $value =~ ^(true|false)$ ]] && echo "$key must be either true or false" >&2 && return 1 |
| 182 | elif [[ $key == 'protocol' ]]; then | 182 | elif [[ $key == 'protocol' ]]; then |
| 183 | [[ ! $value =~ ^(https|ssh)$ ]] && echo 'protocol must be either https or ssh' >&2 && return 1 | 183 | [[ ! $value =~ ^(https|ssh)$ ]] && echo 'protocol must be either https or ssh' >&2 && return 1 |
| 184 | elif [[ $key == 'action' ]]; then | ||
| 185 | value="'$2'" | ||
| 184 | fi | 186 | fi |
| 185 | shift && local target=$key="'$*'" | ||
| 186 | else | 187 | else |
| 187 | echo "Not a valid key for configuration, use <$valid_keys> instead." | 188 | echo "Not a valid key for configuration, use <$valid_keys> instead." |
| 188 | return 1 | 189 | return 1 |
| 189 | fi | 190 | fi |
| 190 | 191 | ||
| 191 | umask 0077 && touch "$CONFIG" | 192 | umask 0077 && touch "$CONFIG" |
| 193 | local target=$key="$value" | ||
| 192 | sed -i'' -e "/^$key=/ d" "$CONFIG" && [[ -n $target ]] && echo "$target" >> "$CONFIG" | 194 | sed -i'' -e "/^$key=/ d" "$CONFIG" && [[ -n $target ]] && echo "$target" >> "$CONFIG" |
| 193 | cat "$CONFIG" | 195 | cat "$CONFIG" |
| 194 | } | 196 | } |