diff options
author | typebrook <typebrook@gmail.com> | 2020-02-05 10:13:55 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-02-05 10:13:55 +0800 |
commit | a2bc06ce83ce314d7acf7c238dc243c3d6816880 (patch) | |
tree | c45857e91a22f2bc571cd66496691ae41ebefa5d | |
parent | 1d71488f7046b7f2c470d64ce821692db9edfef2 (diff) | |
parent | 209a47a0273a153a091b0584722055af6d450707 (diff) |
Merge remote-tracking branch 'origin/dev' into dev
-rw-r--r-- | alias | 4 | ||||
-rwxr-xr-x | scripts/gist | 30 |
2 files changed, 15 insertions, 19 deletions
@@ -59,8 +59,8 @@ alias pi='sudo pip3 install' # nodejs install | |||
59 | # cd to DIRs | 59 | # cd to DIRs |
60 | alias ..='cd ..' | 60 | alias ..='cd ..' |
61 | alias ld='cd -' # last directory | 61 | alias ld='cd -' # last directory |
62 | cdg(){ | 62 | cdg() { |
63 | cd ~/git; cd $1 | 63 | cd ~/git/$1 || cd ~/git |
64 | } | 64 | } |
65 | alias cda='cd ~/data' | 65 | alias cda='cd ~/data' |
66 | alias cdd='cd ~/Downloads' | 66 | alias cdd='cd ~/Downloads' |
diff --git a/scripts/gist b/scripts/gist index 71035dd..5c62a18 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -31,9 +31,8 @@ | |||
31 | 31 | ||
32 | # TODO grep mode for description, file content | 32 | # TODO grep mode for description, file content |
33 | # TODO push github.com (may need new token) | 33 | # TODO push github.com (may need new token) |
34 | # TODO description for current directory | ||
35 | # TODO unit test | 34 | # TODO unit test |
36 | # TODO test on mac and remote machine | 35 | # TODO test on bats, mac and remote machine |
37 | # TODO completion | 36 | # TODO completion |
38 | 37 | ||
39 | # Shell configuration | 38 | # Shell configuration |
@@ -47,23 +46,21 @@ configuredClient="" | |||
47 | 46 | ||
48 | # handle configuration cases | 47 | # handle configuration cases |
49 | _configure() { | 48 | _configure() { |
50 | local target="" | ||
51 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 | 49 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 |
52 | if [[ $1 == 'token' ]]; then | 50 | |
53 | [[ ${#2} -eq 40 ]] && target=$1=$2 \ | 51 | local target="" |
54 | || echo -e Invalid token format, it is not 40 chars '\n' > /dev/tty | 52 | if [[ $1 == 'user' ]]; then |
53 | [[ -z $2 ]] && echo "Must specify username" >&2 && return 1 | ||
54 | elif [[ $1 == 'token' ]]; then | ||
55 | [[ ${#2} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 \ | ||
56 | && return 1 | ||
55 | elif [[ $1 == 'auto_sync' ]]; then | 57 | elif [[ $1 == 'auto_sync' ]]; then |
56 | [[ $2 == 'false' ]] && target=$1=$2 \ | 58 | [[ ! $2 =~ ^(true|false)$ ]] && return 1 |
57 | || target=$1=true | ||
58 | elif [[ $1 == 'folder' ]]; then | ||
59 | [[ -n "$2" ]] && target=$1=$2 \ | ||
60 | || target=$1=~/gist | ||
61 | elif [[ $1 == 'user' ]]; then | ||
62 | target=$1=$2 | ||
63 | fi | 59 | fi |
60 | target=$1=$2 | ||
64 | 61 | ||
65 | umask 0077 && touch $CONFIG | 62 | umask 0077 && touch $CONFIG |
66 | [[ "$target" =~ [^=]$ ]] && sed -i "/^$1=/ d" $CONFIG && echo $target >> $CONFIG | 63 | sed -i "/^$1=/ d" $CONFIG && [[ "$target" =~ [^=]$ ]] && echo $target >> $CONFIG |
67 | cat $CONFIG | 64 | cat $CONFIG |
68 | } | 65 | } |
69 | 66 | ||
@@ -93,6 +90,7 @@ _ask_token() { | |||
93 | _configure token $token | 90 | _configure token $token |
94 | } | 91 | } |
95 | 92 | ||
93 | # check configuration is fine with user setting | ||
96 | _validate_config(){ | 94 | _validate_config(){ |
97 | source $CONFIG 2> /dev/null || true | 95 | source $CONFIG 2> /dev/null || true |
98 | if [[ ! -e $CONFIG || -z $user ]]; then | 96 | if [[ ! -e $CONFIG || -z $user ]]; then |
@@ -161,8 +159,6 @@ http_method() { | |||
161 | } | 159 | } |
162 | 160 | ||
163 | # Show the list of gist, but not updated time | 161 | # Show the list of gist, but not updated time |
164 | # TODO a way to show files | ||
165 | # TODO show git status outdated | ||
166 | _show_list() { | 162 | _show_list() { |
167 | if [[ ! -e $INDEX ]]; then | 163 | if [[ ! -e $INDEX ]]; then |
168 | echo 'No local file found for last update, please run command:' | 164 | echo 'No local file found for last update, please run command:' |
@@ -225,7 +221,7 @@ _parse_response() { | |||
225 | done | 221 | done |
226 | } | 222 | } |
227 | 223 | ||
228 | # TODO add author, files and date of a gist | 224 | # TODO add files and date of a gist |
229 | # get latest list of gists from Github API | 225 | # get latest list of gists from Github API |
230 | _update() { | 226 | _update() { |
231 | echo "fetching $user's gists from $GITHUB_API..." | 227 | echo "fetching $user's gists from $GITHUB_API..." |