diff options
| author | typebrook <typebrook@gmail.com> | 2020-01-18 12:11:40 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-01-18 12:11:40 +0800 |
| commit | 7064bf2f83f8377f0df49f43e6d6344686c34c7d (patch) | |
| tree | 7f33f570af489d64a00452116880d127ee327ab7 | |
| parent | f8e5255f002ba450b004ff8294d1d194e2489571 (diff) | |
update
| -rwxr-xr-x | scripts/gist | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/scripts/gist b/scripts/gist index 39816a5..6038282 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -179,14 +179,22 @@ _show_detail() { | |||
| 179 | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' | 179 | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | _new_file() { | ||
| 183 | tmp_file=$(mktemp) | ||
| 184 | [[ -t 0 ]] && echo "Type a gist. <Ctrl-C> to cancel, <Ctrl-D> when done" | ||
| 185 | cat > $tmp_file | ||
| 186 | echo $tmp_file | ||
| 187 | } | ||
| 188 | |||
| 182 | # create a new gist with files | 189 | # create a new gist with files |
| 183 | # FIXME consider file not exist -> let user type? return 1? | 190 | # FIXME consider file not exist -> let user type? return 1? |
| 184 | _create_gist() { | 191 | _create_gist() { |
| 192 | files="$@" | ||
| 193 | [[ -z "$files" ]] && _new_file | read files | ||
| 194 | echo files: $files | ||
| 185 | echo -n 'description: ' | 195 | echo -n 'description: ' |
| 186 | read DESC | 196 | read DESC |
| 187 | 197 | for file in $files; do | |
| 188 | echo $@ | tr " " "\n" |\ | ||
| 189 | while read file; do | ||
| 190 | FILE=$(basename $file) | 198 | FILE=$(basename $file) |
| 191 | jq --arg FILE "$FILE" '. as $content | { ($FILE): {content: $content} }' -Rs $file | 199 | jq --arg FILE "$FILE" '. as $content | { ($FILE): {content: $content} }' -Rs $file |
| 192 | done |\ | 200 | done |\ |