Skip to content

Instantly share code, notes, and snippets.

@santaklouse
Last active March 27, 2020 00:02
Show Gist options
  • Save santaklouse/05c9f0963dcce65bb8488f85ff922a4c to your computer and use it in GitHub Desktop.
Save santaklouse/05c9f0963dcce65bb8488f85ff922a4c to your computer and use it in GitHub Desktop.
Bash script for making and save screenshots to IPFS, cover with goo.gl link shortener (Linux, macOS). Running IPFS daemon required.

IPFS

IPFS screenshot url

Like cloudapp but using IPFS. If you're asking why IPFS, you should check out ipfs.io. A simple way to think of IPFS is torrents but accessible through HTTP.

Sample IPFS link: https://gateway.ipfs.io/ipfs/QmVqeZQRfcvn8eMZARzRZRxHLignNhS59ksV9vQR3Mmuph/20200326_224139_screenshot.jpg

Setup on Ubuntu

Currently no installer so steps need to be taken manually.

  1. Install IPFS
  2. install xclip, apt-get install xclip
  3. Clone repository, git clone git@github.com:santaklouse/ipfs-screenshot
  4. Start ipfs daemon, ipfs daemon
  5. create keyboard shortcut, System Settings -> Keyboard -> Shortcuts -> Custom Shortcuts -> +
  • command: /{path-to-ipfs-screen}/ipfs-screen.sh

Setup on Mac OS

  1. Install IPFS
  2. Clone repository, git clone git@github.com:santaklouse/ipfs-screenshot
  3. Start ipfs daemon, ipfs daemon

Use

  1. use keyboard shortcut ie: ctrl + shift + s
  2. Select screen area
  3. Paste, ipfs url to the screenshot will be available for use
#!/bin/sh
srcScript=ipfs-screen.sh
bin=ipfs-screenshot
# this script is currently brain dead.
# it merely tries two locations.
# in the future maybe use value of $PATH.
binpath=/usr/local/bin
if [ -d "$binpath" ]; then
cp "$srcScript" "$binpath/$bin"
echo "installed $binpath/$bin"
exit 0
fi
binpath=/usr/bin
if [ -d "$binpath" ]; then
cp "$srcScript" "$binpath/$bin"
echo "installed $binpath/$bin"
exit 0
fi
#!/bin/bash
####
#START
#goo.gl API key
google_api_key=AIzaSyAdr9yOCVcvtPJHA4VkX2gqnmcjXHQosWw
# Shorten a URL using the Google URL Shortener service (http://goo.gl).
goo_gl() {
curl -qsSL -m10 --connect-timeout 10 \
"https://www.googleapis.com/urlshortener/v1/url?key=$google_api_key" \
-H 'Content-Type: application/json' \
-d '{"longUrl": "'$1'"}' \
| \
perl -ne 'if(m/^\s*"id":\s*"(.*)",?$/i) { print $1 }'
}
#END
####
mkdir -p ~/.ipfs-screen/
file=$(`which date` +"%Y%m%d_%H%M%S_screenshot.jpg")
clipboard_command="xclip -selection clipboard"
platform=`uname`
if [[ "$platform" == "Darwin" ]]
then
screencapture -t jpg -i "${HOME}/.ipfs-screen/$file"
clipboard_command="pbcopy"
else
gnome-screenshot -a -f "${HOME}/.ipfs-screen/$file"
fi
[ -f "${HOME}/.ipfs-screen/$file" ] || exit 0
#hash=$(cat "${HOME}/.ipfs-screen/$file" | `which ipfs` add --pin=false -w -q | `which tr` -s '[:space:]' ' ')
hash=$(cat "${HOME}/.ipfs-screen/$file" | `which ipfs` add --stdin-name=$file --pin=false -w --progress=false |awk 'NR==2{print $2"/"}'| { read h; echo $h''$file; })
#hash=$(cat "${HOME}/.ipfs-screen/$file" | `which ipfs` add --stdin-name=$file --pin=false -w --progress=false |awk 'NR==1{print $2"/"$3}')
[ ! $hash ] && exit 0
rm "${HOME}/.ipfs-screen/$file"
ipfs_link="https://gateway.ipfs.io/ipfs/$hash"
short_url=$(goo_gl $ipfs_link)
url=$([ $short_url ] && echo $short_url || echo $ipfs_link)
echo "File ${HOME}/.ipfs-screen/$file added... as $hash ($url)" >> ~/.ipfs-screen/ipfs-add.log
echo -n $url | $clipboard_command > /dev/null
echo $url
proxychains4 curl $url &
#play sound
if [ -t 1 ]
then
/usr/bin/osascript -e "display notification \"$url\" with title \"Screenshot created\""
tput bel
else
afplay "/System/Library/Sounds/Glass.aiff"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment