Add support for hastebin
This commit is contained in:
14
mbin.sh
14
mbin.sh
@@ -3,19 +3,25 @@
|
||||
# Set MKR_BIN if not set. Export it in your shell rc to use a self hosted
|
||||
# instance. Include the trailing slash with custom urls.
|
||||
MKR_BIN=${MKR_BIN:-https://bin.mkr.pw/}
|
||||
HASTEBIN=${HASTEBIN:0}
|
||||
EDITOR=${EDITOR:-vim}
|
||||
|
||||
if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
|
||||
text=$(xclip -selection clipboard -out)
|
||||
op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" $MKR_BIN)
|
||||
op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
|
||||
elif [ -t 0 ]; then
|
||||
tmp_file=$(mktemp)
|
||||
$EDITOR $tmp_file
|
||||
op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" $MKR_BIN)
|
||||
op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
|
||||
rm $tmp_file
|
||||
else
|
||||
op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" $MKR_BIN)
|
||||
op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
|
||||
fi
|
||||
|
||||
link=$(echo $op | cut -f2 -d'/')
|
||||
if [[ $HASTEBIN == 1 ]]; then
|
||||
link=$(echo $op | jq -r .key)
|
||||
else
|
||||
link=$(echo $op | cut -f2 -d'/')
|
||||
fi
|
||||
echo ${MKR_BIN}${link} | tee /dev/tty | xclip -selection clipboard
|
||||
xdg-open ${MKR_BIN}${link}
|
||||
|
||||
Reference in New Issue
Block a user