Something went wrong. Try again.
dotfiles
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159#!/usr/bin/env bashset -euo pipefailerr() { printf "%s\n" "$*" >&2}NAME='sharpshot'SELF="${0:-$NAME}"VERSION='0.0.1'OUTPUT_FILE=${SHARPSHOT_OUTPUT_FILE:-/tmp/sharpshot.png}COMMAND=${SHARPSHOT_COMMAND:-spectacle -b -o ${OUTPUT_FILE}}COPY_COMMAND=${SHARPSHOT_COPY_COMMAND:-wl-copy}FULL_SWITCH=${SHARPSHOT_FULL_SWITCH:--f}ACTIVE_SWITCH=${SHARPSHOT_ACTIVE_SWITCH:--a}REGION_SWITCH=${SHARPSHOT_REGION_SWITCH:--r}VERBOSE=falseDRY=falseverbose() { if $VERBOSE; then printf "%s\n" "$*" fi}full() { verbose 'Capturing full desktop' if $DRY; then echo "DRY-RUN, would execute: '$COMMAND $FULL_SWITCH'" else $COMMAND "$FULL_SWITCH" & fi}active() { verbose 'Capturing active window' if $DRY; then echo "DRY-RUN, would execute: '$COMMAND $ACTIVE_SWITCH'" else $COMMAND "$ACTIVE_SWITCH" & fi}region() { verbose 'Capturing region' if $DRY; then echo "DRY-RUN, would execute: '$COMMAND $REGION_SWITCH'" else $COMMAND "$REGION_SWITCH" & fi}printversion() { echo "$NAME v$VERSION"}usage() { echo 'Usage:' echo " $SELF [options] [action]"}help() { cat <<EOF$(printversion)$(usage)Screenshot helperOptions: -o <PATH> Set the output path to write to -c <COMMAND> Set the base command to use -f <SWITCH> Set the switch to add to the base command for full screen capture -a <SWITCH> Set the switch to add to the base command for active window capture -r <SWITCH> Set the switch to add to the base command for region capture -v Enable verbose logging -d Enable dry-run -h Display this help -V Display versionEOF}while getopts ':hvdVo:c:f:a:r:' option; do case "$option" in v) VERBOSE=true ;; d) DRY=true ;; V) printversion exit ;; h) help exit ;; o) OUTPUT_FILE="$OPTARG" ;; c) COMMAND="$OPTARG" ;; f) FULL_SWITCH="$OPTARG" ;; a) ACTIVE_SWITCH="$OPTARG" ;; r) REGION_SWITCH="$OPTARG" ;; \?) err "Invalid option '$OPTARG'" exit 1 ;; :) err "Missing value for option '$OPTARG'" exit 1 ;; *) usage exit 1 ;; esacdoneshift $((OPTIND - 1))ACTION="${*:-full}"$DRY && echo "$NAME running in dry-run mode"verbose "Outputting to $OUTPUT_FILE"verbose "Base command: $COMMAND"verbose "Full switch: $FULL_SWITCH"verbose "Active switch: $ACTIVE_SWITCH"verbose "Region switch: $REGION_SWITCH"verbose "Action: $ACTION"case "$ACTION" in a*) active ;; r*) region ;; f*) full ;; *) err "Unknown capture mode '$ACTION'" exit 1 ;;esac