|
#!/bin/bash |
|
|
|
# cfg: Folder relative to your keyboard public room. |
|
public_path="/sharex/$(date +"%b%Y")" |
|
|
|
######### Do not touch. ################################################## |
|
|
|
## setup: detect environment and define globals |
|
TMP_FILE="/tmp/push-img.png" |
|
|
|
WWWW="" |
|
KB_TARGETFILE="" |
|
APP="" |
|
for app in spectacle gnome-screenshot |
|
do |
|
[[ -z "$(command -v $app)" ]] && continue |
|
|
|
APP="$app" |
|
break |
|
done |
|
|
|
notify_app_name="Regional Capture" |
|
notify_app_icon="apps.camera-app" |
|
case $APP in |
|
"spectacle") |
|
notify_app_name="Spectacle" |
|
notify_app_icon="org.kde.spectacle" |
|
;; |
|
"gnome-screenshot") |
|
notify_app_name="Screenshot" |
|
notify_app_icon="org.gnome.Screenshot" |
|
;; |
|
esac |
|
|
|
# notify: Instantiates a new push notification. |
|
# $1 string title |
|
# $2 string body |
|
# $3 string? category |
|
notify() |
|
{ |
|
NOTIFY_OPTS="-a $notify_app_name -i $notify_app_icon -c ${3:-transfer} -u normal" |
|
notify-send ${NOTIFY_OPTS} "$1" "$2" & |
|
} |
|
|
|
# fatal: Pushes a fatal notice |
|
# $1 string If $2 present, represents the push title; |
|
# If $2 empty, represents the push body. |
|
# $2 string? Represents the push body. |
|
fatal() |
|
{ |
|
case $# in |
|
1) |
|
notify "$notify_app_name" "$1" "transfer.failed" |
|
;; |
|
2) |
|
notify "$1" "$notify_app_name: $2" "transfer.failed" |
|
;; |
|
esac |
|
} |
|
|
|
|
|
# success: Pushes a success notice |
|
# $1 string If $2 present, represents the push title; |
|
# If $2 empty, represents the push body. |
|
# $2 string? Represents the push body. |
|
success() |
|
{ |
|
case $# in |
|
1) |
|
notify "$notify_app_name" "$1" "transfer.success" |
|
;; |
|
2) |
|
notify "$1" "$notify_app_name: $2" "transfer.success" |
|
;; |
|
esac |
|
} |
|
|
|
|
|
|
|
# info: Pushes a information notice |
|
# $1 string If $2 present, represents the push title; |
|
# If $2 empty, represents the push body. |
|
# $2 string? Represents the push body. |
|
info() |
|
{ |
|
case $# in |
|
1) |
|
notify "$notify_app_name" "$1" "transfer" |
|
;; |
|
2) |
|
notify "$1" "$notify_app_name: $2" "transfer" |
|
;; |
|
esac |
|
} |
|
|
|
|
|
|
|
## setup: globals ## |
|
|
|
# setup_paths: Defines global save info based on new information. |
|
# $1 string filename |
|
setup_paths() |
|
{ |
|
[ ${public_path:0:1} == "/" ] && public_path="${public_path:1}" |
|
|
|
kb_username="$(keybase whoami)" |
|
KB_TARGETFILE=$(keybase config get mountdir | grep -Eo "[\/a-z0-9]+") |
|
KB_TARGETFILE="$KB_TARGETFILE/public/$kb_username/$public_path" |
|
mkdir -p "$KB_TARGETFILE" |
|
|
|
KB_TARGETFILE="$KB_TARGETFILE/$1" |
|
WWW="https://$kb_username.keybase.pub/$public_path/$1" |
|
} |
|
|
|
########################################################################## |
|
|
|
|
|
## fatal: no suitable image capture |
|
if [[ -z $APP ]]; then |
|
notify "Could not find suitable image capture application. Please either install Spectacle (KDE) or gnome-screenshot. (GNOME)" |
|
exit 0 |
|
fi |
|
|
|
# capture: regional capture -> tmp file |
|
case $APP in |
|
"spectacle") |
|
spectacle -brsn -o "$TMP_FILE" |
|
;; |
|
"gnome-screenshot") |
|
gnome-screenshot -ap --file="$TMP_FILE" |
|
;; |
|
esac |
|
|
|
# fatal: user exited/cancelled condition |
|
if [[ $? > 0 || ! -f $TMP_FILE ]]; then |
|
# fatal "Capture cancelled" "Nothing was uploaded to keybase." |
|
exit 0 |
|
fi |
|
|
|
# capture: set real filename |
|
# _affix=$(zenity --entry --text='One Word Category' --entry-text='RegionCapture') |
|
# if [[ $? > 0 ]]; then |
|
# #fatal "Capture cancelled" "Nothing was uploaded to keybase." |
|
# exit 0 |
|
# fi |
|
# |
|
# _affix=$(sed 's/ [a-zA-Z]/\U&/' <<< "$_affix" | sed 's/ //') |
|
# setup_paths "$(date +"$b%d+%H%M%S")_${_affix}.png" |
|
|
|
|
|
# upload: self-explainatory |
|
#cp "$TMP_FILE" "$KB_TARGETFILE" |
|
#success "Upload successful!" "Capture uploaded to $WWW" |
|
|
|
# done: copy URL + photo to clipboard |
|
xclip -selection clipboard -i -t image/png < "$TMP_FILE" |
|
# xclip -selection clipboard -i -t text/plain <<< "$WWW" |
|
|
|
# done: remove file |
|
rm "$TMP_FILE" |