diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gist | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/scripts/gist b/scripts/gist index 284edd0..639709e 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -1,5 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | # define your environmemnts here | ||
3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 4 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
4 | user=typebrook | 5 | user=typebrook |
5 | folder=~/git/gist | 6 | folder=~/git/gist |
@@ -20,6 +21,7 @@ _update() { | |||
20 | } | 21 | } |
21 | 22 | ||
22 | # clone repos which are not in the local | 23 | # clone repos which are not in the local |
24 | # TODO pull if repo is outdated | ||
23 | _sync_repos() { | 25 | _sync_repos() { |
24 | comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ | 26 | comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ |
25 | <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ | 27 | <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ |
@@ -37,13 +39,13 @@ _goto_gist() { | |||
37 | fi | 39 | fi |
38 | 40 | ||
39 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 41 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
40 | echo this gist is at $folder/$GIST_ID | 42 | echo This gist is at $folder/$GIST_ID |
41 | cd $folder/$GIST_ID && tig --all 2> /dev/null | 43 | cd $folder/$GIST_ID && tig --all 2> /dev/null |
42 | } | 44 | } |
43 | 45 | ||
44 | _delete_gist() { | 46 | _delete_gist() { |
45 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 47 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
46 | curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID | 48 | curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID && \ |
47 | _update | 49 | _update |
48 | } | 50 | } |
49 | 51 | ||
@@ -71,23 +73,23 @@ _create_gist() { | |||
71 | }, | 73 | }, |
72 | description: ($DESC) | 74 | description: ($DESC) |
73 | }' -R -s $1 |\ | 75 | }' -R -s $1 |\ |
74 | curl -s -H "$auth_header" --data @- $github_api/gists | 76 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ |
77 | _update | ||
75 | } | 78 | } |
76 | 79 | ||
80 | # update description of a gist | ||
77 | _edit_gist() { | 81 | _edit_gist() { |
78 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 82 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
79 | 83 | ||
80 | jq -n --arg DESC "$2" '{ description: ($DESC) }' |\ | 84 | jq -n --arg DESC "$2" '{ description: ($DESC) }' |\ |
81 | curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null | 85 | curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null && \ |
82 | _update | 86 | _update |
83 | } | 87 | } |
84 | 88 | ||
85 | if [[ $# -eq 0 ]]; then | ||
86 | cat $index | ||
87 | exit 0 | ||
88 | fi | ||
89 | |||
90 | case "$1" in | 89 | case "$1" in |
90 | "") | ||
91 | cat $index | ||
92 | ;; | ||
91 | create | c) | 93 | create | c) |
92 | _create_gist "$2" "$3" | 94 | _create_gist "$2" "$3" |
93 | ;; | 95 | ;; |