summaryrefslogtreecommitdiff
path: root/.local/bin/desktop/dmenu-syncthing-devices
blob: bb93f6dea85da37462de39cdc33aae594a971444 (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
#!/bin/sh

pidof -q syncthing || {
	echo "ERROR: Syncthing is not running" >&2
	exit 2
}

get_devices() {
	for device_id in $(syncthing cli config devices list); do
		printf '%-10s %s\n' \
			"$(syncthing cli config devices "$device_id" name get)" \
			"$device_id"
	done | nl -w1 -s'. '
}

device="$(get_devices | dmenu -l 10 -p "Syncthing devices")"
device_id="${device##* }"
[ -z "$device_id" ] && exit 1

if [ -n "$1" ]; then
	xdotool type "$device_id"
else
	printf '%s\n' "$device_id" | xclip -selection clipboard
	notify-send "📋 Copied to clipboard" "$device_id"
fi