Skip to content

Instantly share code, notes, and snippets.

@sagax
Last active May 26, 2024 16:07
Show Gist options
  • Save sagax/54300d2c835456ca5f847f8eac228879 to your computer and use it in GitHub Desktop.
Save sagax/54300d2c835456ca5f847f8eac228879 to your computer and use it in GitHub Desktop.
paste bashscripts / sharefile scripts
#!/bin/bash
# take API token https://www.toptal.com/developers/hastebin/documentation
TOKENFILE="$HOME/.hastebin"
# example #1
# echo "hello world!" | hastebin
#
# example #2
# hastebin file_for_paste
#
# example #3
# echo "hello world!" | hastebin file_for_paste
function get_token() {
local token
token="$(cat "$TOKENFILE")"
printf "%s" "$token"
}
function get_url() {
local uri
uri="$1"
printf "https://hastebin.com/share/%s" "$uri"
}
function post_data() {
local data
local result
local uri
local url
data="$1"
result="$(curl \
--silent \
--request POST \
--url https://hastebin.com/documents \
--header "Content-Type: text/plain" \
--header "Authorization: Bearer $(get_token)" \
--data "$data")"
if [[ $? -eq 0 ]]
then
uri="$(printf "%b" "$result" | jq -r .key)"
url="$(get_url "$uri")"
printf "%s" "$url" | xclip -sel cli
printf "%s\n" "$url"
else
printf "sorry, but fail\n"
fi
}
function read_and_post_pipe() {
local pipe_data
read -r -d "" pipe_data
post_data "$pipe_data"
}
function read_and_post_file() {
local file_path
local file_data
file_path="$1"
file_data=""
while IFS= read -r line
do
file_data+="$line"$'\n'
done < "$file_path"
post_data "$file_data"
}
function is_has_pipe() {
if [[ -p /dev/stdin ]]
then
return 0
else
return 1
fi
}
function is_has_file() {
if [[ -f "$1" ]]
then
return 0
else
return 1
fi
}
function is_has_args() {
if [[ ${#@} -ge 2 ]]
then
return 0
else
return 1
fi
}
if is_has_pipe "$@"
then
read_and_post_pipe
fi
if is_has_file "$@"
then
read_and_post_file "$1"
fi
if is_has_args "$@"
then
printf ""
fi
#!/bin/bash
result="$(curl -s -F "file=@${1}" https://0x0.st)"
if [[ $? -eq 0 ]]
then
printf "%s" "$result" | xclip -sel cli
printf "%s\n" "$result"
else
printf "sorry, but fail\n"
fi
#!/bin/bash
# take API token https://www.file.io/account/apikeys
APIKEYFILE="$HOME/.fileio"
result=$(curl -s \
-X POST \
-H "accept: application/json" \
-H "Authorization: Bearer $(cat $APIKEYFILE)" \
-H "Content-Type: multipart/form-data" \
-F "file=@${1}" \
-F "expires=10d" \
-F "maxDownloads=1" \
-F "autoDelete=" \
"https://file.io/")
if [[ $? -eq 0 ]]
then
url=$(printf "%s" "$result" | jq -r .link)
printf "%s" "$url" | xclip -sel cli
printf "%s\n" "$url"
else
printf "sorry, but fail\n"
fi
#!/bin/bash
result=$(curl -s -F "file=@${1}" https://tmpfiles.org/api/v1/upload)
if [[ $? -eq 0 ]]
then
url=$(printf "%s" "$result" | jq -r .data.url | awk '{sub(".org", ".org/dl"); printf $0}')
printf "%s" "$url" | xclip -sel cli
printf "%s\n" "$url"
else
printf "sorry, but fail\n"
fi
#!/bin/bash
# example #1
# echo "hello world!" | termbin
#
# example #2
# termbin file_for_paste
#
# example #3
# echo "hello world!" | termbin file_for_paste
function post_data() {
local data
local url
data="$1"
url="$(printf "%s\n" "$data" | netcat termbin.com 9999 | tr -d '\000')"
printf "%s" "$url" | xclip -sel cli
printf "%s\n" "$url"
}
function read_and_post_pipe() {
local pipe_data
read -r -d "" pipe_data
post_data "$pipe_data"
}
function read_and_post_file() {
local file_path
local file_data
file_path="$1"
file_data=""
while IFS= read -r line
do
file_data+="$line"$'\n'
done < "$file_path"
post_data "$file_data"
}
function is_has_pipe() {
if [[ -p /dev/stdin ]]
then
return 0
else
return 1
fi
}
function is_has_file() {
if [[ -f "$1" ]]
then
return 0
else
return 1
fi
}
function is_has_args() {
if [[ ${#@} -ge 2 ]]
then
return 0
else
return 1
fi
}
if is_has_pipe "$@"
then
read_and_post_pipe
fi
if is_has_file "$@"
then
read_and_post_file "$1"
fi
if is_has_args "$@"
then
printf ""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment