dcav-scripts/screenshot.fish

47 lines
1.2 KiB
Fish
Raw Normal View History

2017-09-24 13:52:59 +00:00
#! /usr/bin/fish
2017-04-18 16:16:14 +00:00
# Setup
set SCP_USER "jmaa"
set SRT_USER "j"
# Other stuff
set SCP_PORT "35284"
set SCP_HOST "users.guava.space"
2017-04-18 16:16:14 +00:00
set SCP_PATH "~/public_html/screenshots"
set HTTP_URL "http://dcav.pw/$SRT_USER"
if count $argv > /dev/null
set FILE_EXT $argv[2]
set TEMP_FILE $argv[1]
else
set FILE_EXT ".png"
set TEMP_FILE "/tmp/screenshot_temp"$FILE_EXT
2017-09-24 13:52:59 +00:00
scrot -u $TEMP_FILE
2017-04-18 16:16:14 +00:00
end
# We generate a unique id, by hashing, hexduming, turning that into
# base64 with '_' instead of '/', and only taking the first 3
# characters.
set LINK (sha256sum -b $TEMP_FILE | xxd -r -p | base64 | sed -e "s:/:_:g" | cut -c-3)
2017-04-18 16:16:14 +00:00
set FILENAME $LINK$FILE_EXT
if count $argv > /dev/null
set LINK $FILENAME
end
function display_message
notify-send $argv
end
2017-04-18 16:16:14 +00:00
if test $TEMP_FILE
echo $HTTP_URL$LINK | xclip -i -sel clip
display_message "Screenshot taken. File accessable at '$HTTP_URL$LINK'"
#
set -l msg (scp -o ConnectTimeout=1 -P $SCP_PORT $TEMP_FILE "$SCP_USER@$SCP_HOST:$SCP_PATH/$FILENAME" 2>&1)
if test $status -eq 0
rm $TEMP_FILE
else
display_message "Error occured when attempting to upload screenshot to dcav. File saved into '$TEMP_FILE'. Please see error-message: $msg"
end
2017-04-18 16:16:14 +00:00
end