diff options
author | Andrew Cady <d@jerkface.net> | 2021-09-14 11:04:27 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2021-09-14 11:04:27 -0400 |
commit | 6d505fc790ee719cbf7bac03121b006eb74dcb05 (patch) | |
tree | d59724dba057b4257d952a6d152305eb85ae4671 /dot/local/bin/cutbuffer | |
parent | 847addaf67b82c6e39d9c47518b50c4641212f41 (diff) |
refactor cutbuffer to single file
Diffstat (limited to 'dot/local/bin/cutbuffer')
-rw-r--r-- | dot/local/bin/cutbuffer | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/dot/local/bin/cutbuffer b/dot/local/bin/cutbuffer new file mode 100644 index 0000000..423d974 --- /dev/null +++ b/dot/local/bin/cutbuffer | |||
@@ -0,0 +1,34 @@ | |||
1 | #!/bin/sh | ||
2 | dest_basename=cutbuffer_grab | ||
3 | dest_extension=txt | ||
4 | date_format=+%F_%H%M%S | ||
5 | |||
6 | destdir=$HOME/$dest_basename | ||
7 | |||
8 | cutbuffer_push() | ||
9 | { | ||
10 | now=$(date "$date_format") | ||
11 | dest=$dest_basename.$now.$dest_extension | ||
12 | xcb -p 0 > "$dest" | ||
13 | } | ||
14 | |||
15 | cutbuffer_pop() | ||
16 | { | ||
17 | nameglob=$dest_basename.*.$dest_extension | ||
18 | f=$(find . -maxdepth 1 -type f -name "$nameglob" -print0 | sort -z -V -r | head -z -n 1 | xargs -0) | ||
19 | |||
20 | xcb -s 0 < "$f" | ||
21 | xsel --input < "$f" | ||
22 | |||
23 | mkdir -p .popped | ||
24 | mv "$f" -t .popped | ||
25 | } | ||
26 | |||
27 | set -e | ||
28 | mkdir -p "$destdir" | ||
29 | cd "$destdir" | ||
30 | case "$*" in | ||
31 | pop) cutbuffer_pop ;; | ||
32 | push) cutbuffer_push ;; | ||
33 | esac | ||
34 | |||