Skip to content

Commit

Permalink
Migrate to a smaller haste function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinjasaur committed Apr 4, 2019
1 parent 842ca4f commit 51eee47
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -164,49 +164,9 @@ targz() {
}

# Upload a file to the hastebin service
# Source: https://github.com/diethnis/standalones
haste() {
local output returnfile contents
if (( $# == 0 )) && [[ $(printf "%s" "$0" | wc -c) > 0 ]]
then
contents=$0
elif (( $# != 1 )) || [[ $1 =~ ^(-h|--help)$ ]]
then
echo "Usage: $0 FILE"
echo "Upload contents of plaintext document to hastebin."
echo "\nInvocation with no arguments takes input from stdin or pipe."
echo "Terminate stdin by EOF (Ctrl-D)."
return 1
elif [[ -e $1 && ! -f $1 ]]
then
echo "Error: Not a regular file."
return 1
elif [[ ! -e $1 ]]
then
echo "Error: No such file."
return 1
elif (( $(stat -c %s $1) > (512*1024**1) ))
then
echo "Error: File must be smaller than 512 KiB."
return 1
fi
if [[ -n "$contents" ]] || [[ $(printf "%s" "$contents" | wc -c) < 1 ]]
then
contents=$(cat $1)
fi
output=$(curl -# -f -XPOST "https://hastebin.com/documents" -d"$contents")
if (( $? == 0 )) && [[ $output =~ \"key\" ]]
then
returnfile=$(sed 's/^.*"key":"/https:\/\/hastebin.com\//;s/".*$//' <<< "$output")
if [[ -n $returnfile ]]
then
echo "$returnfile"
return 0
fi
fi
echo "Upload failed."
return 1
}
# Source: https://github.com/seejohnrun/haste-client#lightweight-alternative
# Used like: cat file.txt | haste
haste() { a=$(cat); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}'; }

# Cache $DISPLAY if we're not in tmux, otherwise update from the cache
# Based on: http://alexteichman.com/octo/blog/2014/01/01/x11-forwarding-and-terminal-multiplexers/
Expand Down

0 comments on commit 51eee47

Please sign in to comment.