Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
2.3 KiB

#!/usr/bin/env bash
# forked from Tyler at:
# https://github.com/thcipriani/dotfiles
# https://github.com/thcipriani/dotfiles/commit/1c39af38fafaf24a22474930d18d77edb8931611
#
# TODO:
# [ ] uploads
show_help() {
cat<<USE
USAGE:
grab [screenshotname]
OPTIONS:
--select|-s: use selection rectangle
--public|-p: upload it to https://squiggle.city/~brennen/images/
EXAMPLE:
grab --select --public whatchamajig
USE
}
simple_shot() {
scrot "${_SCREEN_PATH:=$HOME/workspace/screenshots}/Screenshot-%Y-%m-%d-%T.png"
printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/workspace/screenshots}/Screenshot-$(date +%Y-%m-%d-%T).png\n"
}
take_shot() {
default_path="Screenshot-%Y-%m-%d-%T"
if (( $(printf "$path" | wc -c) < 1 )); then
path="$default_path"
grabname=1
else
filename="/${path}.png"
fi
options=''
if (( select == 1 )); then
options="-s"
printf "[\033[38;5;2mSELECT\033[00m] Waiting for your selection\n"
fi
\scrot ${options} "${_SCREEN_PATH:=$HOME/workspace/screenshots}/${path}.png"
if (( grabname == 1 )); then
filename="/Screenshot-$(date +%Y-%m-%d-%T).png"
fi
if (( $public == 1 )); then
make_public "${_SCREEN_PATH:=$HOME/workspace/screenshots}" "$filename"
else
printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/workspace/screenshots}${filename}\n"
fi
}
make_public() {
if ! command -v scp > /dev/null 2>&1; then
printf "[\033[5;38;5;1mERR\033[00m] scp command not found in $PATH\n"
fi
if (( $# < 2 )); then
printf "[\033[5;38;5;1mERR\033[00m] need a path and a folder\n"
fi
scp "${1}${2}" squiggle.city:~/public_html/images/
printf "[\033[38;5;2mURL\033[00m] https://squiggle.city/~brennen/images${2}\n"
}
main () {
if ! command -v scrot > /dev/null 2>&1; then
printf "[\033[5;38;5;1mERR\033[00m] scrot command not found in $PATH\n"
fi
mkdir -p "${_SCREEN_PATH:=$HOME/workspace/screenshots}"
if (( $# == 0 )); then
simple_shot
exit 0
fi
select=0
public=0
while [ -n "$1" ]; do
case "$1" in
--select|-s)
select=1
;;
--public|-p)
public=1
;;
--help|-h)
show_help
exit 0
;;
*)
path="$1"
esac
shift
done
take_shot
}
main "$@"