Skip to content

Instantly share code, notes, and snippets.

@sug0
Last active March 8, 2023 22:12
Show Gist options
  • Select an option

  • Save sug0/82674134a7f4f4a61be28f2e2d2546e8 to your computer and use it in GitHub Desktop.

Select an option

Save sug0/82674134a7f4f4a61be28f2e2d2546e8 to your computer and use it in GitHub Desktop.
Upload screenshots to IPFS
#!/bin/sh
# xshot.sh
# by sugo/vim
usage() {
echo Usage: $0 [-h] "[-select|-full|-edit|-upload]"
}
get_image() {
xclip -selection clipboard -t image/png -o
}
ipfs_lain_add() {
env IPFS_PATH=$HOME/.ipfs-lain \
ipfs add \
--inline \
--fscache \
--raw-leaves \
--cid-version=1 \
$@
}
shorten_lain() {
curl -m 3 -sf -F url=$1 https://s.lain.la | tr -d '\n'
}
shorten_isgd() {
[ $1 ] && (curl -m 3 -sf -F url="$1" https://is.gd/create.php | grep -Po 'https://is.gd/[^"]+' | head -n1 | tr -d '\n')
}
shorten() {
shorten_lain $1 || shorten_isgd $1 || echo $1
}
backend() {
#echo \
# ipfs.lain.la \
# ipfs.lain.ch \
# lain-ipfs.privatevoid.net \
#| xargs shuf -n1 -e
echo gandas.us.to
}
cd /tmp
case $1 in
-h)
usage
exit 0
;;
-select)
scrot -a $(slop -f '%x,%y,%w,%h') -e 'xclip -selection clipboard -t image/png -i $f && rm -f $f'
;;
-full)
scrot -e 'xclip -selection clipboard -t image/png -i $f && rm -f $f'
;;
-edit)
pic=$(date +%s).png
get_image > $pic
azpainter $pic
xclip -selection clipboard -t image/png -i $pic
rm -f $pic
;;
-upload)
cid=$(get_image | ipfs_lain_add | tail -n1 | awk '{print $2}')
echo $cid >> $HOME/.ipfs-lain-screenshots
shorten https://$(backend)/ipfs/$cid | xclip -selection clipboard
notify-send Screenshot "Upload complete"
;;
*)
usage
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment