summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-01-24 16:44:06 +0800
committertypebrook <typebrook@gmail.com>2020-01-24 16:44:06 +0800
commit83b430a3ca8c74cf2a5e3f28a636bb2e1a7079f9 (patch)
tree3947a7404b03d647528278a642395f958d6a80ef /scripts/gist
parent8d0958696859744312e15c6c017accd97a32be7e (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist14
1 files changed, 6 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist
index 2b21f91..34e4330 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -62,15 +62,15 @@ config=~/.config/gistrc
62# TODO support access token from input or web 62# TODO support access token from input or web
63_auth() { 63_auth() {
64 local data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}" 64 local data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}"
65 read -p "Github username: " user 65 read -p "Github username: " user < /dev/tty
66 read -sp "Github password: " password 66 read -sp "Github password: " password < /dev/tty
67 mkdir -p ~/.config && umask 0077 && echo user=$user > $config 67 mkdir -p ~/.config && umask 0077 && echo user=$user > $config
68 68
69 curl https://api.github.com/authorizations \ 69 curl https://api.github.com/authorizations \
70 --user "$user:$password" \ 70 --user "$user:$password" \
71 --data "$data" > /dev/null 71 --data "$data" > /dev/null
72 72
73 read -p "2-factor code: " OTP 73 read -p "2-factor code: " OTP < /dev/tty
74 curl https://api.github.com/authorizations \ 74 curl https://api.github.com/authorizations \
75 --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ 75 --user "$user:$password" -H "X-GitHub-OTP: $OTP" \
76 --data "$data" |\ 76 --data "$data" |\
@@ -237,8 +237,7 @@ _new_file() {
237 tmp_file=$(mktemp) 237 tmp_file=$(mktemp)
238 cat > $tmp_file 238 cat > $tmp_file
239 echo -e '\n' > /dev/tty 239 echo -e '\n' > /dev/tty
240 # FIXME when file content is from STDIN, read fails 240 [[ -z "$1" ]] && read -p 'Type file name: ' filename < /dev/tty
241 [[ -z "$1" ]] && read -p 'Type file name: ' filename
242 mv $tmp_file /tmp/$filename 241 mv $tmp_file /tmp/$filename
243 echo /tmp/$filename 242 echo /tmp/$filename
244} 243}
@@ -248,8 +247,7 @@ _new_file() {
248_create_gist() { 247_create_gist() {
249 _set_gist "$@" 248 _set_gist "$@"
250 [[ -z "$files" ]] && files=$(_new_file $filename) 249 [[ -z "$files" ]] && files=$(_new_file $filename)
251 # FIXME when file content is from STDIN, read fails 250 [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty
252 [[ -z "$description" ]] && read -p 'Type description: ' description
253 251
254 for file in $files; do 252 for file in $files; do
255 FILE=$(basename $file) 253 FILE=$(basename $file)
@@ -273,7 +271,7 @@ _edit_gist() {
273 _gist_id $1 271 _gist_id $1
274 272
275 echo -n 'Type new description: ' 273 echo -n 'Type new description: '
276 read DESC 274 read DESC < /dev/tty
277 jq -n --arg DESC "$DESC" '{ description: ($DESC) }' \ 275 jq -n --arg DESC "$DESC" '{ description: ($DESC) }' \
278 | curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null && \ 276 | curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null && \
279 _update 277 _update