summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-09-14 02:17:18 -0400
committerAndrew Cady <d@jerkface.net>2021-09-14 02:17:18 -0400
commit6d82b20fc9f9922abc14202a5eca08f4e3298227 (patch)
treee66260ed3c0c0935b636529a78f57f327ac5892c
parentcddfcca3838898e8c718ea2d3c0eccfe9f1e34db (diff)
cutbuffer_push: cleanup
-rwxr-xr-xdot/local/bin/cutbuffer_push56
1 files changed, 7 insertions, 49 deletions
diff --git a/dot/local/bin/cutbuffer_push b/dot/local/bin/cutbuffer_push
index f7e1e69..62faf7b 100755
--- a/dot/local/bin/cutbuffer_push
+++ b/dot/local/bin/cutbuffer_push
@@ -1,68 +1,26 @@
1#!/bin/sh 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=cutbuffer_grab 2default_basename=cutbuffer_grab
7default_extension=txt 3default_extension=txt
8date_format=+%F_%H%M%S 4date_format=+%F_%H%M%S
9SCREEN_GRAB_DEST_DIR=$HOME/$default_basename 5
6destdir=$HOME/$default_basename
10 7
11chdir_to_destination() 8chdir_to_destination()
12{ 9{
13 [ -d "$SCREEN_GRAB_DEST_DIR" ] || mkdir -p "$SCREEN_GRAB_DEST_DIR" 10 [ -d "$destdir" ] || mkdir -p "$destdir"
14 cd "$SCREEN_GRAB_DEST_DIR" 11 cd "$destdir"
15} 12}
16 13
17choose_destination() 14choose_destination()
18{ 15{
19 local stamp basename extension now 16 local stamp basename extension now
20 case $# in 17 now=$(date "$date_format")
21 1) ;; 18 DESTINATION=$default_basename.$now.$default_extension
22 0) now=$(date "$date_format")
23 DESTINATION=$default_basename.$now.$default_extension
24 return
25 ;;
26 *) return 1 ;;
27 esac
28
29 case "$1" in
30 *.*)
31 basename=${1%.*}
32 extension=${1##*.}
33 ;;
34 *)
35 basename=$1
36 extension=$default_extension
37 ;;
38 esac
39 DESTINATION=$basename.$extension
40}
41
42get_out_the_way()
43{
44 local stamp basename extension destination
45 [ -e "$1" ] || return 0
46
47 stamp=$(date -r "$1" "$date_format") || return
48 case "$1" in
49 *.*)
50 basename=${1%.*}
51 extension=${1##*.}
52 destination=$basename.$stamp.$extension
53 ;;
54 *)
55 destination=$1.$stamp
56 ;;
57 esac
58 [ ! -e "$destination" ] || return
59 mv "$1" "$destination"
60} 19}
61 20
62set -e 21set -e
63 22
64chdir_to_destination 23chdir_to_destination
65choose_destination "$@" 24choose_destination
66get_out_the_way "$DESTINATION"
67xcb -p 0 > "$DESTINATION" 25xcb -p 0 > "$DESTINATION"
68 26