aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rwxr-xr-xclip34
2 files changed, 35 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 4208232..19780cc 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ SCRIPTS = addressgrep \
4 battery-checknow \ 4 battery-checknow \
5 battery-status \ 5 battery-status \
6 brightness \ 6 brightness \
7 clip \
7 config-backup \ 8 config-backup \
8 dmenu-bookmarks \ 9 dmenu-bookmarks \
9 dmenu-dwm-sessionmanager \ 10 dmenu-dwm-sessionmanager \
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