Browse Source

Add support for hastebin

master
Ceda ei 6 years ago
parent
commit
ee6193620b
  1. 6
      README.md
  2. 12
      mbin.sh

6
README.md

@ -1,6 +1,7 @@
# mkr-bin-client # mkr-bin-client
Command line client for [mkr/bin](https://github.com/MKRhere/bin). Uses Command line client for [mkr/bin](https://github.com/MKRhere/bin) and
[hastebin](https://github.com/seejohnrun/haste-server/). Uses
[bin.mkr.pw](https://bin.mkr.pw) as the default instance. [bin.mkr.pw](https://bin.mkr.pw) as the default instance.
## Requirements ## Requirements
@ -22,7 +23,8 @@ Copy `mbin.sh` to your PATH or add an alias to point to the absolute path of
## Customization ## Customization
+ To use custom instance, export `MKR_BIN` variable. + To use custom instance, export `MKR_BIN` variable. Also, set `HASTEBIN=1` if
it is a hastebin instance.
+ Add `export MKR_BIN="https://bin.example.com/"` (Ensure to keep the + Add `export MKR_BIN="https://bin.example.com/"` (Ensure to keep the
trailing slash) in your shell rc (`~/.bashrc` if using bash). trailing slash) in your shell rc (`~/.bashrc` if using bash).
+ To use an editor other than vim in interactive mode, export `EDITOR` variable. + To use an editor other than vim in interactive mode, export `EDITOR` variable.

12
mbin.sh

@ -3,19 +3,25 @@
# Set MKR_BIN if not set. Export it in your shell rc to use a self hosted # 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. # instance. Include the trailing slash with custom urls.
MKR_BIN=${MKR_BIN:-https://bin.mkr.pw/} MKR_BIN=${MKR_BIN:-https://bin.mkr.pw/}
HASTEBIN=${HASTEBIN:0}
EDITOR=${EDITOR:-vim} EDITOR=${EDITOR:-vim}
if [[ $1 == "-c" || $1 == "--clipboard" ]]; then if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
text=$(xclip -selection clipboard -out) 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 elif [ -t 0 ]; then
tmp_file=$(mktemp) tmp_file=$(mktemp)
$EDITOR $tmp_file $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 rm $tmp_file
else 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 fi
if [[ $HASTEBIN == 1 ]]; then
link=$(echo $op | jq -r .key)
else
link=$(echo $op | cut -f2 -d'/') link=$(echo $op | cut -f2 -d'/')
fi
echo ${MKR_BIN}${link} | tee /dev/tty | xclip -selection clipboard echo ${MKR_BIN}${link} | tee /dev/tty | xclip -selection clipboard
xdg-open ${MKR_BIN}${link}

Loading…
Cancel
Save