Skip to content

Instantly share code, notes, and snippets.

@shizeeg
Last active December 15, 2015 15:18
Show Gist options
  • Save shizeeg/5280431 to your computer and use it in GitHub Desktop.
Save shizeeg/5280431 to your computer and use it in GitHub Desktop.
Take screenshot, upload to narod.ru then show link on the terminal.
#!/bin/sh
# http://help.yandex.ru/narod/creating/ftp.xml
#
LOGIN=
PASS=
LFTP=/usr/bin/lftp
SCROT=/usr/bin/scrot
SCROTOPTS=
REMOTEDIR=
IMGDIR="/tmp/"
SCREENSHOT="$IMGDIR/$1"
if [ -z $LOGIN ];then
LOGIN=$USER
fi
IMGHOST="$LOGIN.narod2.ru"
FTPHOST="$LOGIN.ftp.narod.ru"
if [ -z $1 ];then
SCREENSHOT="$IMGDIR/$(date --rfc-3339=date)-$(mktemp -u --suffix=.png XXX)"
fi
if [ -z $DISPLAY ];then
export DISPLAY=127.1:0.0
fi
# Check dependencies.
if [ ! -x $LFTP ];then
echo $LFTP "not found!"
exit 1
fi
if [ ! -x $SCROT ];then
echo $SCROT "not found!"
exit 2
fi
# Redirect all output to stdrerr, so ftpscrot | xclip should work.
$SCROT $SCROTOPTS "$SCREENSHOT" >&2
if [ -z $PASS ];then
read -s -p "Enter password: " PASS
fi
if [ $? -eq 0 ];then
echo "put $SCREENSHOT" | $LFTP -u $LOGIN:$PASS "$FTPHOST/$REMOTEDIR"
fi
if [ $? -eq 0 ]; then
IMG=$(basename "$SCREENSHOT")
# strip http(s):// prefix to add it later.
LINK=$(echo $IMGHOST | sed -r -e 's|https?://||g')
echo "http://$LINK/$REMOTEDIR/$IMG" | sed -e 's|//|/|2g'
fi
# vim: sw=2:ts=2:et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment