-
-
Save kylestev/03ea4402c7f1f69cd181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function get_clipboard_content { | |
xclip -selection c -o | |
} | |
function upload_pastie { | |
local lang="plain_text" | |
local content=$(get_clipboard_content) | |
local private=1 | |
local auth="burger" | |
url=$(curl -X POST http://pastie.org/pastes \ | |
-F "paste[parser_id]=$lang" \ | |
-F "paste[body]=$content" \ | |
-F "paste[restricted]=$private" \ | |
-F "paste[authorization]=$auth" \ | |
-s -L -o /dev/null -w "%{url_effective}") | |
echo "$url" | xclip -selection c | |
nohup xdg-open "$url" > nohup.out 2>&1 | |
} | |
function upload_imgur { | |
local client_id="550953eefa6bdbd" | |
curl -X POST https://api.imgur.com/3/upload \ | |
-H "Authorization: Client-ID $client_id" \ | |
-F "image=@$1" | |
} | |
function get_imgur_id { | |
echo "$1" | grep -o -P '(?<="id":").*?(?=",)' | |
} | |
function imgur_process { | |
local json_output=$(upload_imgur $2) | |
local imgur_id=$(get_imgur_id $json_output) | |
local renamed="$1$imgur_id.png" | |
local url="http://i.imgur.com/$imgur_id.png" | |
mv $2 $renamed | |
echo "$url" | xclip -selection c | |
nohup xdg-open "$url" > nohup.out 2>&1 | |
} | |
if [ "$1" = "-p" ]; then | |
upload_pastie | |
else | |
tmp_dir="/tmp/clippy/" | |
tmp_screenshot="${tmp_dir}screenshot.png" | |
mkdir -p "$tmp_dir" | |
if [ "$1" = "-s" ]; then | |
gnome-screenshot -f $tmp_screenshot | |
elif [ "$1" = "-w" ]; then | |
gnome-screenshot -w -f $tmp_screenshot | |
elif [ "$1" = "-a" ]; then | |
gnome-screenshot -a -f $tmp_screenshot | |
fi | |
if [ -f $tmp_screenshot ]; then | |
imgur_process $tmp_dir $tmp_screenshot | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment