-
-
Save RGBD/1e4aafe9b2b554887e16061558567950 to your computer and use it in GitHub Desktop.
pb --- ptpb.pw pastebin wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pb_url='http://ptpb.pw' | |
echo2() { echo "$@" 1>&2; } | |
usage() { | |
name="$(basename "$0")" | |
echo2 "$name: pastes to or fetches text from '$pb_url'" | |
echo2 "usage: $name [path]" | |
echo2 "with no arguments, $name pastes input and prints short path" | |
echo2 "with one argument, $name fetches data referenced by path" | |
echo2 "If path contains slashes, it will be interpreted as url" | |
} | |
pb_short_path() { | |
short_url=$(cat | grep "^url:" | awk '{print $2;}') | |
echo "${short_url#$pb_url/}" | |
} | |
main() { | |
if [[ $# == 0 ]]; then # expect input | |
curl -F c=@- "$pb_url" | pb_short_path | |
elif [[ $# == 1 ]]; then # provide output | |
if [[ "$1" == "--help" || "$1" == "-h" ]]; then | |
usage | |
return | |
fi | |
arg="$1" | |
if [[ "$arg" == *"/"* ]]; then | |
url_to_fetch="$arg" | |
else | |
url_to_fetch="$pb_url/$arg" | |
fi | |
curl "$url_to_fetch" | |
else | |
usage | |
fi | |
} | |
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | |
main "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment