diff options
-rwxr-xr-x | scripts/gist | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/scripts/gist b/scripts/gist index 55c9ab8..88bc7b9 100755 --- a/scripts/gist +++ b/scripts/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 | ||