aboutsummaryrefslogtreecommitdiff
path: root/clip
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-02-11 17:54:22 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2022-02-11 17:54:22 +0100
commit8d65aa80aaa523eba71ac84d72bee269260508b9 (patch)
tree72ab1ebe1683d99c7b6bf7a0e3d4367286cbc79b /clip
parentf18383243b2da10f537b090e49100e1f96affd93 (diff)
downloadscripts-8d65aa80aaa523eba71ac84d72bee269260508b9.tar.gz
scripts-8d65aa80aaa523eba71ac84d72bee269260508b9.zip
Added clip, a primitive clipboard manager
Diffstat (limited to 'clip')
-rwxr-xr-xclip34
1 files changed, 34 insertions, 0 deletions
diff --git a/clip b/clip
new file mode 100755
index 0000000..eff2d6f
--- /dev/null
+++ b/clip
@@ -0,0 +1,34 @@
1#!/bin/sh
2
3# A primitive clipboard manager. Saves the current selection to a temporary
4# file and shows all saved selections in dmenu for the user to select one.
5# It does not check for duplicates and it fails if there it can't
6# create the temporary directory with the designated name.
7
8# Requires: xsel, dmenu
9
10# TODO: improve formatting in dmenu
11
12menu="dmenu"
13menuopts="-l 25"
14
15dir="/tmp/clipdir"
16mkdir -p "$dir"
17
18file="$(mktemp -p $dir $(date +%s).XXXXX)"
19xsel > "$file"
20
21list="$(mktemp)"
22ls $dir > $list;
23
24lines="$(mktemp)"
25for f in $dir/*; do
26 nlines=$(expr 1 + "$(wc -l $f | awk '{print $1}')")
27 fclean=$(echo $f | sed "s|$dir\/||")
28 printf "$fclean ($nlines) | $(head -n 1 $f)\n" >> "$lines"
29done
30
31selected=$(sort -r $lines | $menu $menuopts | awk '{print $1}')
32if [ -n "$selected" ]; then
33 xsel -ib < "$dir/$selected"
34fi

Generated with cgit - Back to sebastiano.tronto.net