summaryrefslogtreecommitdiff
path: root/qmenu/qmenu_vm/fqvm_appmenus
blob: 4d3fe4662a7cdb398d416f2fc8537833ec1b49f9 (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
option=1

while [ -n "$option" ]; do

	option=$(printf 'Available\nSelected\nRefresh' | dmenu-unlinked -i -l 3 -p "$qube:")

	if [ "$option" = Available ]; then

		applications=1

		while [ -n "$applications" ]; do

			applications=$(qvm-appmenus --get-available --i-understand-format-is-unstable "$qube" | grep -v "$(qvm-appmenus --get-whitelist --i-understand-format-is-unstable "$qube")" | dmenu-unlinked -l 50 -p "$qube:" | cut -f1 -d\ )

			if [ -n "$applications" ]; then

				# Check validity of input to prevent whitelisted-appmenus.list
 				# from being filled with garbage.
				qvm-appmenus --get-available --i-understand-format-is-unstable "$qube" | cut -f1 -d\  | grep -q "^$applications$" &&

					printf "\n$applications" >> "$HOME"/.local/share/qubes-appmenus/"$qube"/whitelisted-appmenus.list

					applications_modified=1
			fi
		done

	elif [ "$option" = Selected ]; then

		applications=1

		while [ -n "$applications" ]; do

			applications=$(qvm-appmenus --get-available --i-understand-format-is-unstable "$qube" | grep "$(qvm-appmenus --get-whitelist --i-understand-format-is-unstable "$qube")" | dmenu-unlinked -l 50 -p "$qube:"  | cut -f1 -d\ )

			if [ -n "$applications" ]; then

				for application in $applications; do

					# Look up linenumber above $application in
					# whitelisted-appmenus.list to delete if it is garbage whitespace.
					whitespace=$(grep -n1 "^$application$" < "$HOME"/.local/share/qubes-appmenus/"$qube"/whitelisted-appmenus.list | sed '1q;d' | cut -d- -f1)

					sed -i "${whitespace}{/^$/d;}" "$HOME"/.local/share/qubes-appmenus/"$qube"/whitelisted-appmenus.list
					sed -i "/$application/d" "$HOME"/.local/share/qubes-appmenus/"$qube"/whitelisted-appmenus.list

					applications_modified=1
				done
			fi
		done

	elif [ "$option" = Refresh ]; then

		qvm-appmenus -q --force --update "$qube"
	fi

	# Only update qvm-appmenus down here, *after* the user
	# has quit the application selection to improve speed and reduce unnecessary updates.
	if [ -n "$applications_modified" ]; then

		qvm-appmenus -q --update "$qube"

		unset applications_modified
	fi
done