blob: eff2d6fa83f90927ca3f371f46570a8af940841b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/bin/sh
# A primitive clipboard manager. Saves the current selection to a temporary
# file and shows all saved selections in dmenu for the user to select one.
# It does not check for duplicates and it fails if there it can't
# create the temporary directory with the designated name.
# Requires: xsel, dmenu
# TODO: improve formatting in dmenu
menu="dmenu"
menuopts="-l 25"
dir="/tmp/clipdir"
mkdir -p "$dir"
file="$(mktemp -p $dir $(date +%s).XXXXX)"
xsel > "$file"
list="$(mktemp)"
ls $dir > $list;
lines="$(mktemp)"
for f in $dir/*; do
nlines=$(expr 1 + "$(wc -l $f | awk '{print $1}')")
fclean=$(echo $f | sed "s|$dir\/||")
printf "$fclean ($nlines) | $(head -n 1 $f)\n" >> "$lines"
done
selected=$(sort -r $lines | $menu $menuopts | awk '{print $1}')
if [ -n "$selected" ]; then
xsel -ib < "$dir/$selected"
fi
|