From 2be80ffa48ec4422c108956cebec96f53e9f7986 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 15 May 2020 23:02:07 +0800 Subject: Add remarkable prefix for temp files --- gist | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gist b/gist index e883087..7c1db22 100755 --- a/gist +++ b/gist @@ -48,7 +48,6 @@ # Since now a gist is a local cloned repo # It is your business to do git commit and git push -# TODO Named temp file # TODO feature to exclude tag-value or grep-string # TODO codebase statistics, like C++ or something # 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 # Mac compatibility tmp_file() { if [[ $(uname) == Darwin ]]; then - file=$(mktemp) && mv $(mktemp) $tmp_dir && echo $tmp_dir/$(basename $file) + TMPDIR=$tmp_dir mktemp -t $1 else - mktemp -p $tmp_dir + mktemp -p $tmp_dir -t $1.XXXXXX fi } tac() { @@ -133,7 +132,7 @@ http_method() { [[ $METHOD =~ (POST|PATCH) ]] && data_opt="@$http_data" http -b "$METHOD" "$@" "$header" "$data_opt" ;; esac 2>&1 \ - | tee $(tmp_file) \ + | tee $(tmp_file HTTP.$METHOD) \ || { echo "Error: no active internet connection" >&2; return 1; } } @@ -629,7 +628,7 @@ _set_gist() { # Let user type the content of gist before setting filename _new_file() { - tmp_file=$(tmp_file) + tmp_file=$(tmp_file CREATE) if [[ -z $INPUT ]]; then echo "Type a gist. to cancel, when done" > /dev/tty cat > "$tmp_file" @@ -664,7 +663,7 @@ _create_gist() { [[ -z $description ]] && read -e -r -p 'Type description: ' description < /dev/tty echo 'Creating a new gist...' - http_data=$(tmp_file) + http_data=$(tmp_file PATLOAD.CREATE) echo -e "${files[*]}\n$description" \ | _gist_body > "$http_data" \ && http_method POST $GITHUB_API/gists \ @@ -697,7 +696,7 @@ _edit_gist() { DESC="$@" fi - http_data=$(tmp_file) + http_data=$(tmp_file PAYLOAD.EDIT) echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" new_record=$(http_method PATCH "$GITHUB_API/gists/$GIST_ID" \ | sed -e '1 s/^/[/; $ s/$/]/' \ -- cgit v1.2.3-70-g09d2