aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xgist33
1 files changed, 16 insertions, 17 deletions
diff --git a/gist b/gist
index 55c9ab8..ad08016 100755
--- a/gist
+++ b/gist
@@ -1,6 +1,6 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# Author: Hsieh Chin Fan (typebrook) 3# Author: Hsieh Chin Fan (typebrook) <typebrook@gmail.com>
4# License: MIT 4# License: MIT
5# https://gist.github.com/typebrook/b0d2e7e67aa50298fdf8111ae7466b56 5# https://gist.github.com/typebrook/b0d2e7e67aa50298fdf8111ae7466b56
6# 6#
@@ -10,8 +10,8 @@
10# 10#
11# Use the following commands to manage your gists: 11# Use the following commands to manage your gists:
12# 12#
13# * update your gists list with Github API 13# * update the local list of your gists, star for your starred gists
14# gist [update | u] 14# gist (update | u) [star | s]
15# 15#
16# * list your gists with format: [number] [url] [file_num] [comment_num] [short description] 16# * list your gists with format: [number] [url] [file_num] [comment_num] [short description]
17# gist 17# gist
@@ -191,16 +191,6 @@ _show_detail() {
191 jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' 191 jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}'
192} 192}
193 193
194_new_file() {
195 [[ -t 0 ]] && echo "Type a gist. <Ctrl-C> to cancel, <Ctrl-D> when done" > /dev/tty
196 tmp_file=$(mktemp)
197 cat > $tmp_file
198 echo
199 [[ -z "$1" ]] && echo -en '\nType file name: ' > /dev/tty && read filename
200 mv $tmp_file /tmp/$filename
201 echo /tmp/$filename
202}
203
204_set_gist() { 194_set_gist() {
205 while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in 195 while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
206 -d | --desc) 196 -d | --desc)
@@ -215,12 +205,22 @@ _set_gist() {
215 files=$@ 205 files=$@
216} 206}
217 207
208_new_file() {
209 [[ -t 0 ]] && echo "Type a gist. <Ctrl-C> to cancel, <Ctrl-D> when done" > /dev/tty
210 tmp_file=$(mktemp)
211 cat > $tmp_file
212 echo -e '\n' > /dev/tty
213 [[ -z "$1" ]] && echo -n 'Type file name: ' > /dev/tty && read filename
214 mv $tmp_file /tmp/$filename
215 echo /tmp/$filename
216}
217
218# create a new gist with files 218# create a new gist with files
219# FIXME error handling if gist is not created 219# FIXME error handling if gist is not created
220_create_gist() { 220_create_gist() {
221 _set_gist "$@" 221 _set_gist "$@"
222 [[ -z $files ]] && files=$(_new_file $filename) 222 [[ -z $files ]] && files=$(_new_file $filename)
223 [[ -z $description ]] && echo -en '\nDescription: ' && read description 223 [[ -z $description ]] && echo -n 'Type description: ' && read description
224 224
225 for file in $files; do 225 for file in $files; do
226 FILE=$(basename $file) 226 FILE=$(basename $file)
@@ -235,8 +235,7 @@ _create_gist() {
235 sed '1 s/^/[/; $ s/$/]/' |\ 235 sed '1 s/^/[/; $ s/$/]/' |\
236 _parse_response |\ 236 _parse_response |\
237 sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index && \ 237 sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index && \
238 echo Gist created 238 echo -e '\nGist created'
239 echo
240 _show_list $index | tail -1 239 _show_list $index | tail -1
241} 240}
242 241
@@ -259,7 +258,7 @@ case "$1" in
259 "") 258 "")
260 _show_list $index ;; 259 _show_list $index ;;
261 star | s) 260 star | s)
262 _show_list $starred ;; 261 _show_list $starred ;;
263 update | u) 262 update | u)
264 _update "$2" ;; 263 _update "$2" ;;
265 new | n) 264 new | n)