bin-client/mbin.sh

22 lines
725 B
Bash
Raw Normal View History

2018-11-16 10:12:06 +01:00
#!/usr/bin/env bash
# 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/}
2018-11-16 10:26:36 +01:00
EDITOR=${EDITOR:-vim}
2018-11-16 10:56:30 +01:00
if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
text=$(xclip -selection clipboard -out)
op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" $MKR_BIN)
elif [ -t 0 ]; then
2018-11-16 10:26:36 +01:00
tmp_file=$(mktemp)
$EDITOR $tmp_file
2018-11-16 10:41:47 +01:00
op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" $MKR_BIN)
2018-11-16 10:26:36 +01:00
rm $tmp_file
else
2018-11-16 10:41:47 +01:00
op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" $MKR_BIN)
2018-11-16 10:26:36 +01:00
fi
2018-11-16 10:12:06 +01:00
link=$(echo $op | cut -f2 -d'/')
echo ${MKR_BIN}${link} | tee /dev/tty | xclip -selection clipboard