|
@@ -0,0 +1,87 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+
|
|
3
|
+. $(ffoom path)
|
|
4
|
+
|
|
5
|
+ffoo import config
|
|
6
|
+ffoo import pretty
|
|
7
|
+
|
|
8
|
+STORAGE_DIR="$HOME/.local/share/saturnin/clips"
|
|
9
|
+
|
|
10
|
+usage() {
|
|
11
|
+ usage_is "save [-1|-2|-c]"
|
|
12
|
+ usage_is "load [-1|-2|-c] name"
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+clipln() {
|
|
16
|
+ #
|
|
17
|
+ # Print desired clipboard(s) and \n
|
|
18
|
+ #
|
|
19
|
+ case $1 in
|
|
20
|
+ primary|secondary|clipboard)
|
|
21
|
+ xclip -o -selection $1 2>/dev/null
|
|
22
|
+ ;;
|
|
23
|
+ ALL)
|
|
24
|
+ xclip -o -selection primary 2>/dev/null
|
|
25
|
+ xclip -o -selection secondary 2>/dev/null
|
|
26
|
+ xclip -o -selection clipboard 2>/dev/null
|
|
27
|
+ ;;
|
|
28
|
+ esac
|
|
29
|
+ echo ""
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+save_clip() {
|
|
33
|
+ local clipname=$1
|
|
34
|
+ mkdir -p "$STORAGE_DIR" || die "could not create directory for saving"
|
|
35
|
+ local path="$STORAGE_DIR/$(date +%Y%m%d-%H%M%S.clip)"
|
|
36
|
+ clipln $clipname > "$path"
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+lsclips() {
|
|
40
|
+ local clipname=$1
|
|
41
|
+ local ft hint name
|
|
42
|
+ test -d "$STORAGE_DIR" || return 0
|
|
43
|
+ ls "$STORAGE_DIR/"*.clip 2>/dev/null \
|
|
44
|
+ | while read name;
|
|
45
|
+ do
|
|
46
|
+ ft=$(file -b -i $name | cut -d\; -f1)
|
|
47
|
+ case $ft in
|
|
48
|
+ text/*)
|
|
49
|
+ hint=$(head -c 80 $name | tr '\n' '↵')
|
|
50
|
+ ;;
|
|
51
|
+ *)
|
|
52
|
+ hint=$(head -c 16 $name | hexdump -C)
|
|
53
|
+ ;;
|
|
54
|
+ esac
|
|
55
|
+ echos "$(basename $name) || $ft || $hint"
|
|
56
|
+ done
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+load_clip() {
|
|
60
|
+ local clipname=$1
|
|
61
|
+ local fname=$(saturnin clip ls | saturnin dmenu | cut -d\ -f 1)
|
|
62
|
+ cat $STORAGE_DIR/$name | xclip -i -selection $clipname
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+clipname=primary
|
|
66
|
+action=ls
|
|
67
|
+while true; do case "$1" in
|
|
68
|
+ save) action=save; shift ;;
|
|
69
|
+ load) action=load; shift ;;
|
|
70
|
+ ls) action=list; shift ;;
|
|
71
|
+ -1) clipname=primary; shift ;;
|
|
72
|
+ -2) clipname=secondary; shift ;;
|
|
73
|
+ -c) clipname=clipboard; shift ;;
|
|
74
|
+ "") break; ;;
|
|
75
|
+ *) usage; ;;
|
|
76
|
+esac done
|
|
77
|
+
|
|
78
|
+debug "\$@='$@'"
|
|
79
|
+debug -v clipname action
|
|
80
|
+
|
|
81
|
+case $action in
|
|
82
|
+ save) save_clip $clipname ;;
|
|
83
|
+ load) load_clip $clipname ;;
|
|
84
|
+ list) lsclips ;;
|
|
85
|
+esac
|
|
86
|
+
|
|
87
|
+
|