aboutsummaryrefslogtreecommitdiff
path: root/clip
diff options
context:
space:
mode:
Diffstat (limited to '')
-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