From e90ea86d15de5941d6fab333b1ca8faa58d5e348 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 16 Nov 2018 15:26:30 +0530 Subject: [PATCH] Add clipboard mode. --- README.md | 2 ++ mbin.sh | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56df37e..a3ddbc4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Copy `mbin.sh` to your PATH or add an alias to point to the absolute path of ```bash some_command | mbin.sh mbin.sh # Opens in interactive mode. + mbin.sh -c # Posts clipboard contents to bin + mbin.sh --clipboard # Posts clipboard contents to bin ``` ## Customization diff --git a/mbin.sh b/mbin.sh index 0068afe..a96f252 100755 --- a/mbin.sh +++ b/mbin.sh @@ -5,7 +5,10 @@ MKR_BIN=${MKR_BIN:-https://bin.mkr.pw/} EDITOR=${EDITOR:-vim} -if [ -t 0 ]; then +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 tmp_file=$(mktemp) $EDITOR $tmp_file op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" $MKR_BIN)