#!/bin/sh set -eu usage() { cat <<-'EOF' Usage: shot [-m] shot -h EOF } help() { cat <<-'EOF' Options: -m use the mouse to select the region to screen shot -h, --help show this message Take a screenshot. The default is to print the whole screen, but the "-m" can be given to select only a part of the screen. The screenshots are saved to ~/Pictures/Screenshots/ Examples: Take screenshot of the full screen: $ shot Select the region of the screenshot: $ shot -m EOF } for flag in "$@"; do case "$flag" in (--) break ;; (--help) usage help exit ;; (*) ;; esac done OPTS= while getopts 'mh' flag; do case "$flag" in (m) OPTS='-s' ;; (h) usage help exit ;; (*) usage >&2 exit 2 ;; esac done shift $((OPTIND - 1)) TEMPLATE=~/Pictures/Screenshots/%Y-%m-%dT%H:%M:%S.png mkdir -p "$(dirname "$TEMPLATE")" scrot $OPTS "$TEMPLATE" msg -D "screenshot saved on ~/Pictures/Screenshots/"