From 447d62d60ff1d602302118091df699ab1f2f1519 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 24 Nov 2020 06:03:14 -0500 Subject: im: screenshot wrapper --- dot/local/bin/im | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 dot/local/bin/im (limited to 'dot/local/bin/im') diff --git a/dot/local/bin/im b/dot/local/bin/im new file mode 100644 index 0000000..88b9cb1 --- /dev/null +++ b/dot/local/bin/im @@ -0,0 +1,72 @@ +#!/bin/sh + +# A screen-grab will be saved in $SCREEN_GRAB_DEST_DIR if set, otherwise +# in $HOME/screen_grab/ if it exsts; otherwise $HOME. + +default_basename=screen_grab +default_extension=png +date_format=+%F_%H%M%S + +chdir_to_destination() +{ + local d + d=$HOME/$default_basename + if [ "$SCREEN_GRAB_DEST_DIR" ] + then cd "$SCREEN_GRAB_DEST_DIR" + elif [ -d "$d" ] + then cd "$d" + else cd + fi +} + +choose_destination() +{ + local stamp basename extension now + case $# in + 1) ;; + 0) now=$(date "$date_format") + DESTINATION=$default_basename.$now.$default_extension + return + ;; + *) return 1 ;; + esac + + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + ;; + *) + basename=$1 + extension=$default_extension + ;; + esac + DESTINATION=$basename.$extension +} + +get_out_the_way() +{ + local stamp basename extension destination + [ -e "$1" ] || return 0 + + stamp=$(date -r "$1" "$date_format") || return + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + destination=$basename.$stamp.$extension + ;; + *) + destination=$1.$stamp + ;; + esac + [ ! -e "$destination" ] || return + mv "$1" "$destination" +} + +set -e + +chdir_to_destination +choose_destination "$@" +get_out_the_way "$DESTINATION" +exec import "$DESTINATION" -- cgit v1.2.3