summaryrefslogtreecommitdiff
path: root/dot/local/bin/im
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-11-24 06:03:14 -0500
committerAndrew Cady <d@jerkface.net>2020-11-24 06:03:14 -0500
commit447d62d60ff1d602302118091df699ab1f2f1519 (patch)
tree3e5df318acfd265adf7cd0234c378610b7634117 /dot/local/bin/im
parentb39ee0fb7e77e74d688b34c3a4fe02f2a6131f19 (diff)
im: screenshot wrapper
Diffstat (limited to 'dot/local/bin/im')
-rw-r--r--dot/local/bin/im72
1 files changed, 72 insertions, 0 deletions
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 @@
1#!/bin/sh
2
3# A screen-grab will be saved in $SCREEN_GRAB_DEST_DIR if set, otherwise
4# in $HOME/screen_grab/ if it exsts; otherwise $HOME.
5
6default_basename=screen_grab
7default_extension=png
8date_format=+%F_%H%M%S
9
10chdir_to_destination()
11{
12 local d
13 d=$HOME/$default_basename
14 if [ "$SCREEN_GRAB_DEST_DIR" ]
15 then cd "$SCREEN_GRAB_DEST_DIR"
16 elif [ -d "$d" ]
17 then cd "$d"
18 else cd
19 fi
20}
21
22choose_destination()
23{
24 local stamp basename extension now
25 case $# in
26 1) ;;
27 0) now=$(date "$date_format")
28 DESTINATION=$default_basename.$now.$default_extension
29 return
30 ;;
31 *) return 1 ;;
32 esac
33
34 case "$1" in
35 *.*)
36 basename=${1%.*}
37 extension=${1##*.}
38 ;;
39 *)
40 basename=$1
41 extension=$default_extension
42 ;;
43 esac
44 DESTINATION=$basename.$extension
45}
46
47get_out_the_way()
48{
49 local stamp basename extension destination
50 [ -e "$1" ] || return 0
51
52 stamp=$(date -r "$1" "$date_format") || return
53 case "$1" in
54 *.*)
55 basename=${1%.*}
56 extension=${1##*.}
57 destination=$basename.$stamp.$extension
58 ;;
59 *)
60 destination=$1.$stamp
61 ;;
62 esac
63 [ ! -e "$destination" ] || return
64 mv "$1" "$destination"
65}
66
67set -e
68
69chdir_to_destination
70choose_destination "$@"
71get_out_the_way "$DESTINATION"
72exec import "$DESTINATION"