dotfiles/bin/.local/bin/shp

28 lines
695 B
Plaintext
Raw Normal View History

2021-12-21 21:21:51 -05:00
#!/usr/bin/env sh
set -eu
# Things you need: ~/.config/sr.ht file, curl, jq, xclip
. ~/.config/sr.ht
PASTESRHT=${PASTESRHT:-https://paste.sr.ht}
2021-12-26 23:23:42 -05:00
fname=$(zenity --title="Upload" --text="File name:" --entry)
2021-12-21 21:21:51 -05:00
result=$(xclip -o -sel clip --no-newline | jq -sR '{
"files": [
{
"contents": .,
"filename": "'"$fname"'",
}
],
"visibility": "unlisted"
}' | curl \
-H Authorization:"token $legacy_token" \
-H Content-Type:application/json \
-X POST \
-d @- $PASTESRHT/api/pastes)
printf '%s\n' "$result"
sha=$(printf '%s' "$result" | jq -r .sha)
user=$(printf '%s' "$result" | jq -r .user.canonical_name)
xdg-open "$PASTESRHT/$user/$sha"
echo "$PASTESRHT/$user/$sha" | xclip -sel clip