aboutsummaryrefslogtreecommitdiff
path: root/clipboardUtils.sh
blob: 1789905edb571834f5208a8beb024db6741dfee5 (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
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

# Manipulate the X selection
# Dependencies: dmenu, xsel

options="Show selections\nReplicate selections\nWrite to selection\n"
selections="Clipboard\nPrimary\nSecondary\n"

target="$(printf "$options" | dmenu -l 3 -p "~ Clipboard utils ~")"
[ "$target" = "" ] && exit 0

case "$target" in

	"Show selections") notify-send "Clipboard: [$(xsel -bo)]
Primary: [$(xsel -po)]
Secondary: [$(xsel -so)]" ;;

	"Replicate selections")
		fromSelection="$(printf "$selections" | dmenu -l 3 -p "From selection:")"
		[ "$fromSelection" = "" ] && exit 0
		case "$fromSelection" in
			"Clipboard") fromOption=b ;;
			"Primary")  fromOption=p ;;
			"Secondary") fromOption=s ;;
		esac
		toSelection="$(printf "$selections" | dmenu -l 3 -p "To selection:")"
		[ "$toSelection" = "" ] && exit 0
		case "$toSelection" in
			"Clipboard") toOption=b ;;
			"Primary")  toOption=p ;;
			"Secondary") toOption=s ;;
		esac
		xsel -"$fromOption"o | xsel -"$toOption"i && notify-send "Copied [$(xsel -"$toOption"o)] from $fromSelection to $toSelection." ;;

	"Write to selection")
		selectedSelection="$(printf "$selections" | dmenu -l 3 -p "Write to which selection?")"
		textToWrite="$(dmenu -p "Text to write to $selectedSelection:")"
		[ "$textToWrite" = "" ] && exit 0
		case "$selectedSelection" in
			"Clipboard") echo "$textToWrite" | xsel -bi ;;
			"Primary")  echo "$textToWrite" | xsel -pi ;;
			"Secondary") echo "$textToWrite" | xsel -si ;;
		esac
		notify-send "Written [$textToWrite] to $selectedSelection." ;;

esac