Skip to content

Instantly share code, notes, and snippets.

@shreve
Last active October 3, 2018 19:52
Show Gist options
  • Save shreve/1d9ff5ec544ec1ae2e2dcb42e15b1092 to your computer and use it in GitHub Desktop.
Save shreve/1d9ff5ec544ec1ae2e2dcb42e15b1092 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Requirements:
# scrot (for screenshots)
# byzanz-record (for gif recordings)
pic_format="/home/jacob/Pictures/screenshots/%Y-%m-%d--%H-%M-%S--\$wx\$h.png"
gif_duration=10
gif_format=$(date +"/home/jacob/Pictures/screenshots/%Y-%m-%d--%H-%M-%S--${gif_duration}s.gif")
client_id=c9a6efb3d7932fd
perform_upload() {
curl -s -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=@$1" https://api.imgur.com/3/image.xml
}
upload() {
if response=$(perform_upload "$1"); then
url="${response##*<link>}"
url="${url%%</link>*}"
echo $url
else
echo "$response"
echo "Error uploading $1"
exit 1
fi
}
case "$1" in
"pic")
filename=$(scrot -s -e 'echo $f' $pic_format)
url=$(upload $filename)
echo $url
echo $url | xsel -i --clipboard
;;
"gif")
if [ ! -z "$2" ]; then
gif_duration="$2"
fi
byzanz-record --duration=$gif_duration --delay=2 "$gif_format"
url=$(upload $gif_format)
echo $url
echo $url | tee | xsel -i --clipboard
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment