aboutsummaryrefslogtreecommitdiffstats
path: root/lpass_copy.sh
blob: 9499dec1a325c0fc323d1966a6b85343eccf1f43 (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
#!/usr/bin/env bash

error() {
	echo "$@"
	exit 1
}

if [[ -z $1 ]]; then
	error "Error: nothing to copy"
fi

if [[ -n $WAYLAND_DISLPLAY ]]; then
	command=(wl-copy)
	if [[ $X_SELECTION == primary ]]; then
		command+=( --primary )
	fi
elif [[ -n $DISPLAY ]]; then
	command=(xclip -selection clipboard)
else
	error "Error: X11 or Wayland display were not detected"
fi

echo "$1" | "${command[@]}" || error "Error: failed to copy data to clipboard"
echo "Password copied to clipboard."