summaryrefslogtreecommitdiff
path: root/dot/local/bin/cutbuffer
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-09-14 11:04:27 -0400
committerAndrew Cady <d@jerkface.net>2021-09-14 11:04:27 -0400
commit6d505fc790ee719cbf7bac03121b006eb74dcb05 (patch)
treed59724dba057b4257d952a6d152305eb85ae4671 /dot/local/bin/cutbuffer
parent847addaf67b82c6e39d9c47518b50c4641212f41 (diff)
refactor cutbuffer to single file
Diffstat (limited to 'dot/local/bin/cutbuffer')
-rw-r--r--dot/local/bin/cutbuffer34
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
2dest_basename=cutbuffer_grab
3dest_extension=txt
4date_format=+%F_%H%M%S
5
6destdir=$HOME/$dest_basename
7
8cutbuffer_push()
9{
10 now=$(date "$date_format")
11 dest=$dest_basename.$now.$dest_extension
12 xcb -p 0 > "$dest"
13}
14
15cutbuffer_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
27set -e
28mkdir -p "$destdir"
29cd "$destdir"
30case "$*" in
31 pop) cutbuffer_pop ;;
32 push) cutbuffer_push ;;
33esac
34