diff options
| -rwxr-xr-x | gist | 13 |
1 files changed, 6 insertions, 7 deletions
| @@ -48,7 +48,6 @@ | |||
| 48 | # Since now a gist is a local cloned repo | 48 | # Since now a gist is a local cloned repo |
| 49 | # It is your business to do git commit and git push | 49 | # It is your business to do git commit and git push |
| 50 | 50 | ||
| 51 | # TODO Named temp file | ||
| 52 | # TODO feature to exclude tag-value or grep-string | 51 | # TODO feature to exclude tag-value or grep-string |
| 53 | # TODO codebase statistics, like C++ or something | 52 | # TODO codebase statistics, like C++ or something |
| 54 | # TODO migrate to gh-page, with install.sh and check_md5 in README | 53 | # TODO migrate to gh-page, with install.sh and check_md5 in README |
| @@ -83,9 +82,9 @@ trap "[[ '$DEBUG' == 'true' ]] && find $tmp_dir -type f | xargs tail -n +1 > lo | |||
| 83 | # Mac compatibility | 82 | # Mac compatibility |
| 84 | tmp_file() { | 83 | tmp_file() { |
| 85 | if [[ $(uname) == Darwin ]]; then | 84 | if [[ $(uname) == Darwin ]]; then |
| 86 | file=$(mktemp) && mv $(mktemp) $tmp_dir && echo $tmp_dir/$(basename $file) | 85 | TMPDIR=$tmp_dir mktemp -t $1 |
| 87 | else | 86 | else |
| 88 | mktemp -p $tmp_dir | 87 | mktemp -p $tmp_dir -t $1.XXXXXX |
| 89 | fi | 88 | fi |
| 90 | } | 89 | } |
| 91 | tac() { | 90 | tac() { |
| @@ -133,7 +132,7 @@ http_method() { | |||
| 133 | [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data" | 132 | [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data" |
| 134 | http -b "$METHOD" "$@" "$header" "$data_opt" ;; | 133 | http -b "$METHOD" "$@" "$header" "$data_opt" ;; |
| 135 | esac 2>&1 \ | 134 | esac 2>&1 \ |
| 136 | | tee $(tmp_file) \ | 135 | | tee $(tmp_file HTTP.$METHOD) \ |
| 137 | || { echo "Error: no active internet connection" >&2; return 1; } | 136 | || { echo "Error: no active internet connection" >&2; return 1; } |
| 138 | } | 137 | } |
| 139 | 138 | ||
| @@ -629,7 +628,7 @@ _set_gist() { | |||
| 629 | 628 | ||
| 630 | # Let user type the content of gist before setting filename | 629 | # Let user type the content of gist before setting filename |
| 631 | _new_file() { | 630 | _new_file() { |
| 632 | tmp_file=$(tmp_file) | 631 | tmp_file=$(tmp_file CREATE) |
| 633 | if [[ -z $INPUT ]]; then | 632 | if [[ -z $INPUT ]]; then |
| 634 | echo "Type a gist. <Ctrl-C> to cancel, <Ctrl-D> when done" > /dev/tty | 633 | echo "Type a gist. <Ctrl-C> to cancel, <Ctrl-D> when done" > /dev/tty |
| 635 | cat > "$tmp_file" | 634 | cat > "$tmp_file" |
| @@ -664,7 +663,7 @@ _create_gist() { | |||
| 664 | [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty | 663 | [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty |
| 665 | 664 | ||
| 666 | echo 'Creating a new gist...' | 665 | echo 'Creating a new gist...' |
| 667 | http_data=$(tmp_file) | 666 | http_data=$(tmp_file PATLOAD.CREATE) |
| 668 | echo -e "${files[*]}\n$description" \ | 667 | echo -e "${files[*]}\n$description" \ |
| 669 | | _gist_body > "$http_data" \ | 668 | | _gist_body > "$http_data" \ |
| 670 | && http_method POST $GITHUB_API/gists \ | 669 | && http_method POST $GITHUB_API/gists \ |
| @@ -697,7 +696,7 @@ _edit_gist() { | |||
| 697 | DESC="$@" | 696 | DESC="$@" |
| 698 | fi | 697 | fi |
| 699 | 698 | ||
| 700 | http_data=$(tmp_file) | 699 | http_data=$(tmp_file PAYLOAD.EDIT) |
| 701 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" | 700 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" |
| 702 | new_record=$(http_method PATCH "$GITHUB_API/gists/$GIST_ID" \ | 701 | new_record=$(http_method PATCH "$GITHUB_API/gists/$GIST_ID" \ |
| 703 | | sed -e '1 s/^/[/; $ s/$/]/' \ | 702 | | sed -e '1 s/^/[/; $ s/$/]/' \ |