summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-02-04 14:32:04 +0800
committertypebrook <typebrook@gmail.com>2020-02-04 14:32:04 +0800
commit218d1aa9d2a07da4f849037fa311415a1cf066d3 (patch)
tree729e98440137a199f3d46bf9586dbffbfbe347b7
parentb12e63ae39f92254fd294d21e177bef88d0fe054 (diff)
update
-rwxr-xr-xscripts/gist71
1 files changed, 25 insertions, 46 deletions
diff --git a/scripts/gist b/scripts/gist
index b6e2df0..2ae69f8 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -4,51 +4,29 @@
4# License: MIT 4# License: MIT
5# https://gist.github.com/typebrook/b0d2e7e67aa50298fdf8111ae7466b56 5# https://gist.github.com/typebrook/b0d2e7e67aa50298fdf8111ae7466b56
6# 6#
7# gist
8# Description: Host your gists as local cloned git repo
9# Usage: gist [command] [<arg>]
7# 10#
8# This script host your gists as local cloned git repo 11# [star | s] list your gists with format below, star for your starred gists:
9# It works under GNU curl, which is easy to get in most cases 12# update [star | s] update the local list of your gists, star for your starred gists
13# [number] [url] [file_num] [comment_num] [short description]
14# <index_of_gist> show the path of local gist repo and files
15# new [-d | --desc "<gist-description>"] <files>...
16# create a new gist with files
17# new [-d | --desc "<gist-description>"] [-f | --file <file_name>] < <file-with-content>
18# create a new gist from STDIN
19# detail <index_of_gist> show the detail of a gist
20# edit <index_of_gist> edit a gist description
21# delete <index_of_gist>... delete a gist
22# clean clean removed gists in local
23# config [token | user | folder | auto-sync |EDITOR | action [value] ]
24# configuration
25# user <user> get gists from a given Github user
26# help show this help message
10# 27#
11# Use the following commands to manage your gists: 28# Since now a gist is a local cloned repo
12# 29# It is your business to do git commit and git push
13# * update the local list of your gists, star for your starred gists
14# gist (update | u) [star | s]
15#
16# * list your gists with format: [number] [url] [file_num] [comment_num] [short description]
17# gist [star | s]
18#
19# * show the path of local gist repo and files
20# gist <index_of_gist>
21#
22# * create a new gist with files
23# gist (new | n) [-d | --desc "<gist-description>"] <files>...
24#
25# * create a new gist with STDIN
26# gist (new | n) [-d | --desc "<gist-description>"] [-f | --file <file>] < <file-with-content>
27#
28# * show the detail of a gist
29# gist (detail | d) <index_of_gist>
30#
31# * edit a gist description
32# gist (edit | e) <index_of_gist>
33#
34# * delete a gist
35# gist (delete | D) <index_of_gist>...
36#
37# * clean removed gists in local
38# gist (clean | C)
39#
40# * update a gist
41# Since now a gist is a local cloned repo
42# It is your business to do git commit and git push
43#
44# * configuration
45# gist (config | c) [token|user|folder|auto-sync|EDITOR|action [value]]
46#
47# * get gists from a given Github user
48# gist (user | U) <user>
49#
50# * show this help message
51# gist (help | h)
52 30
53# TODO grep mode for description, file content 31# TODO grep mode for description, file content
54# TODO push github.com (may need new token) 32# TODO push github.com (may need new token)
@@ -190,8 +168,8 @@ _show_list() {
190 echo ' gist update' 168 echo ' gist update'
191 return 0 169 return 0
192 fi 170 fi
193 local filter='/^s/ d' 171 local filter='/^s/ d; /^$/ d'
194 [[ $1 == "s" ]] && filter='/^[^s]/ d' 172 [[ $1 == "s" ]] && filter='/^[^s]/ d; /^$/ d'
195 173
196 while read index link blob_code file_num extra description; do 174 while read index link blob_code file_num extra description; do
197 local repo=$folder/$(echo $link | sed 's#.*/##') 175 local repo=$folder/$(echo $link | sed 's#.*/##')
@@ -207,6 +185,7 @@ _show_list() {
207 echo -e $index $link $file_num $extra $(echo $description | cut -c -$(( 60 -$occupy -1 )) ) 185 echo -e $index $link $file_num $extra $(echo $description | cut -c -$(( 60 -$occupy -1 )) )
208 done < $INDEX \ 186 done < $INDEX \
209 | sed "$filter" 187 | sed "$filter"
188 echo -e '\nrun "gist help" for more details'
210} 189}
211 190
212# parse JSON from STDIN with string of commands 191# parse JSON from STDIN with string of commands
@@ -464,7 +443,7 @@ _edit_gist() {
464} 443}
465 444
466usage() { 445usage() {
467 sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 446 sed -E -n ' /^$/ q; 7,$ s/^#//p' $0
468} 447}
469 448
470getConfiguredClient 449getConfiguredClient