Skip to content

Instantly share code, notes, and snippets.

@moonexpr
Last active November 12, 2022 19:26
Show Gist options
  • Save moonexpr/ba13dc8fb975db3b6dd9848a263472e9 to your computer and use it in GitHub Desktop.
Save moonexpr/ba13dc8fb975db3b6dd9848a263472e9 to your computer and use it in GitHub Desktop.
Screencap: An quick and simple image upload utility
#!/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"

🌈 install

  1. Open up your terminal.
  2. Type echo $PATH and pick one of these.
  3. wget https://gist.githubusercontent.com/wholesome-wiz/ba13dc8fb975db3b6dd9848a263472e9/raw/a09f76835e4f99a9d8e15af3677a25e6909bfa02/screencap -o$HOME/.local/bin/screencap (grab the script)
  4. chmod u+x ~/.local/bin/screencap (make it an executable)
  5. Bind F1 or what have you to issue this command: screencap
  6. Done.
@moonexpr
Copy link
Author

image

@moonexpr
Copy link
Author

moonexpr commented Sep 24, 2022

P.S make sure you have xclip and keybass installed. - kthx bye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment