aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2020-07-03 14:35:03 +0800
committerHsieh Chin Fan <typebrook@gmail.com>2020-07-03 16:54:33 +0800
commit52a4535aef22494cbd14e411e71e51ae8cf82a7c (patch)
treee2d2319a101f6fe93fba13406936396cbbb34c4d
parent4e0539c1488e1e84deb2be221d0acc420c5818c6 (diff)
Set default editor as vim, or vi if not exist
-rwxr-xr-xgist9
1 files changed, 5 insertions, 4 deletions
diff --git a/gist b/gist
index b54aaaa..4a22ed6 100755
--- a/gist
+++ b/gist
@@ -153,7 +153,7 @@ _process_json() {
153 153
154# Handle configuration cases 154# Handle configuration cases
155_configure() { 155_configure() {
156 [[ $# == 0 ]] && ${EDITOR:-vi} $CONFIG && return 0 156 [[ $# == 0 ]] && ${EDITOR} $CONFIG && return 0
157 157
158 local key=$1; local value="$2"; valid_configs=${VALID_CONFIGS[@]} 158 local key=$1; local value="$2"; valid_configs=${VALID_CONFIGS[@]}
159 [[ ! ${key} =~ ^(${valid_configs// /|})$ ]] \ 159 [[ ! ${key} =~ ^(${valid_configs// /|})$ ]] \
@@ -207,9 +207,6 @@ _validate_config() {
207 echo 'To get user starred gists, a token is needed' >&2 && return 1 207 echo 'To get user starred gists, a token is needed' >&2 && return 1
208 _ask_token 208 _ask_token
209 fi 209 fi
210
211 [[ -z $folder || ! -w $(dirname "$folder") ]] && folder=~/gist && mkdir -p $folder
212 INDEX=$folder/index; [[ -e $INDEX ]] || touch $INDEX
213} 210}
214 211
215# Apply current configuration into config file 212# Apply current configuration into config file
@@ -241,6 +238,10 @@ _apply_config() {
241 _validate_config "$@" || return 1 238 _validate_config "$@" || return 1
242 _reformat_config 239 _reformat_config
243 240
241 [[ -z $folder || ! -w $(dirname "$folder") ]] && folder=~/gist && mkdir -p $folder
242 INDEX=$folder/index; [[ -e $INDEX ]] || touch $INDEX
243 EDITOR=${EDITOR:-$(type vim &>/dev/null && echo vim || echo vi)}
244
244 getConfiguredClient 245 getConfiguredClient
245} 246}
246 247