blob: 4f952477d5fd5c3b096edc2b66fc839ffcf76970 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/bin/sh
get_qube_label() {
qube_label=$(grep -s "^$(qvm-prefs "$qube" label)=" "$HOME"/.config/qmenu.conf | cut -d= -f2)
[ -z "$qube_label" ] && qube_label='#000000'
}
case $1 in
--all)
qube_list=$(qvm-ls --no-spinner --running -O name,label | grep -v '^dom0 \|^sys-usb' | sed '1d; s/ red/ 1\@ /g; s/ orange/ 2\@ /g; s/ yellow/ 3\@ /g; s/ green/ 4\@ /g; s/ gray/ 5\@ /g; s/ blue/ 6\@ /g; s/ purple/ 7\@ /g; s/ black/ 8\@ /g' | sort -k2,2 | sed 's/ 1\@ / red/g; s/ 2\@ / orange/g; s/ 3\@ / yellow/g; s/ 4\@ / green/g; s/ 5\@ / gray/g; s/ 6\@ / blue/g; s/ 7\@ / purple/g; s/ 8\@ / black/g');;
--focused)
qube=$(xprop -id "$(xdotool getwindowfocus)" _QUBES_VMNAME | cut -f2 -d\")
[ "$qube" = '_QUBES_VMNAME: not found.' ] && exit 2;;
*)
printf "Usage: $0 [OPTION]\nList and manage your connected devices via dmenu.\n\n --all\n --focused\n\n"
[ "$1" = --help ] && exit 0; exit 2
esac
while :; do
device=$(echo "$(qvm-block ls | sed -e 's/^/|block| /' & qvm-device mic ls | sed -e 's/^/|mic| /' & qvm-usb ls | sed -e 's/^/|usb| /')" | sort -r -k1,2 | dmenu-unlinked -l 32) || exit 1
device_type=$(echo "$device" | cut -d\| -f2)
if [ -n "$device" ] && [ "$(echo "$device" | wc -l)" -eq 1 ]; then
device_id=$(echo "$device" | cut -f2 -d\ )
if [ "$device_type" = block ]; then
device_name=$(echo "$device" | awk '{print $3,$4}')
holding_qube=$(echo "$device" | awk '{print $5}')
else
device_name=$(echo "$device" | awk '{print $3}')
holding_qube=$(echo "$device" | awk '{print $4}')
fi
if [ -z "$holding_qube" ]; then
if [ "$1" = --all ]; then
qube=$(echo "$qube_list" | dmenu-unlinked -p "attach to:" -l 32 | cut -f1 -d\ )
fi
if [ -n "$qube" ]; then
get_qube_label
if [ "$(printf 'No\nYes' | dmenu-unlinked -sb "$qube_label" -i -p "Attach '$device_name' to $qube?")" = Yes ]; then
qvm-device "$device_type" attach -q "$qube" "$device_id" && exit 0
echo Quit... | dmenu-unlinked -p "Error: Failed to attach device!" > /dev/null 2>&1
exit 2
fi
fi
elif [ "$1" = --all ] || [ "$holding_qube" = "$qube" ]; then
get_qube_label
if [ "$(printf 'No\nYes' | dmenu-unlinked -sb "$qube_label" -i -p "Detach '$device_name' from $holding_qube?")" = Yes ]; then
qvm-device "$device_type" detach -q "$holding_qube" "$device_id" && exit 0
echo Quit... | dmenu-unlinked -p "Error: Failed to detach device!" > /dev/null 2>&1
exit 2
fi
else
get_qube_label
if [ "$(printf 'No\nYes' | dmenu-unlinked -sb "$qube_label" -i -p "Detach '$device_name' from $holding_qube and attach it to $qube?")" = Yes ]; then
qvm-device "$device_type" detach -q "$holding_qube" "$device_id" &&
qvm-device "$device_type" attach -q "$qube" "$device_id" && exit 0
echo Quit... | dmenu-unlinked -p "Error: Failed to handle device!" > /dev/null 2>1&
exit 2
fi
fi
fi
done
|