diff options
Diffstat (limited to 'dot/local/bin')
-rwxr-xr-x | dot/local/bin/cutbuffer_pop | 62 |
1 files changed, 4 insertions, 58 deletions
diff --git a/dot/local/bin/cutbuffer_pop b/dot/local/bin/cutbuffer_pop index 6a693c6..f817c08 100755 --- a/dot/local/bin/cutbuffer_pop +++ b/dot/local/bin/cutbuffer_pop | |||
@@ -1,62 +1,12 @@ | |||
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 | |||
6 | default_basename=cutbuffer_grab | 2 | default_basename=cutbuffer_grab |
7 | default_extension=txt | 3 | default_extension=txt |
8 | date_format=+%F_%H%M%S | 4 | destdir=$HOME/$default_basename |
9 | SCREEN_GRAB_DEST_DIR=$HOME/$default_basename | ||
10 | 5 | ||
11 | chdir_to_destination() | 6 | chdir_to_destination() |
12 | { | 7 | { |
13 | [ -d "$SCREEN_GRAB_DEST_DIR" ] || mkdir -p "$SCREEN_GRAB_DEST_DIR" | 8 | [ -d "$destdir" ] || mkdir -p "$destdir" |
14 | cd "$SCREEN_GRAB_DEST_DIR" | 9 | cd "$destdir" |
15 | } | ||
16 | |||
17 | choose_destination() | ||
18 | { | ||
19 | local stamp basename extension now | ||
20 | case $# in | ||
21 | 1) ;; | ||
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 | |||
42 | get_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 | } | 10 | } |
61 | 11 | ||
62 | extract() | 12 | extract() |
@@ -64,15 +14,11 @@ extract() | |||
64 | sort -z -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | cut -d' ' -f2 | 14 | sort -z -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | cut -d' ' -f2 |
65 | } | 15 | } |
66 | 16 | ||
67 | |||
68 | set -e | 17 | set -e |
69 | 18 | ||
70 | chdir_to_destination | 19 | chdir_to_destination |
71 | 20 | ||
72 | f=$(find . -maxdepth 1 -type f -printf "%C@ %h/%f\0" | extract) | 21 | f=$(find . -maxdepth 1 -type f -name 'cutbuffer_grab.*.txt' -printf "%C@ %h/%f\0" | extract) |
73 | |||
74 | set -x | ||
75 | exec 2> /tmp/cbp.log | ||
76 | 22 | ||
77 | xcb -s 0 < "$f" | 23 | xcb -s 0 < "$f" |
78 | xsel --input < "$f" | 24 | xsel --input < "$f" |