summaryrefslogtreecommitdiff
path: root/qubes-dwm-6.2/scripts/dmenu_cur
blob: 49f35494ebe073fe73a30811c1a2cb11c5a9652e (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
#!/bin/sh

get_colour() {
  local colour=$(xprop -id $1 | grep '_QUBES_LABEL_COLOR(CARDINAL)' | cut -d\  -f3)
  printf "#%06X" $colour
}

app_path() {
  if [ "$1" = "dom0" ]; then
    echo "$HOME/.local/share/applications/" ;
  else
    echo "$HOME/.local/share/qubes-appmenus/$1"/apps/ ;
  fi;
}

scrape_apps() {
  grep '^Name=\|^Exec=' "$(app_path $1)"/*.desktop | filter |  grep ':Name=' \
  | sed 's/'"$1"': //' | cut -d= -f2- | sort
}

filter() {
  grep -v "Qube Settings\|os\.vm\.debian-11-dvm\|os\.vm\.whonix-ws-16"
}


find_file() {
  grep "^Name=.*$2" "$(app_path $1)"/*.desktop | filter | cut -d: -f1
}

# Expects the contents of a desktop file
execute_app() {
  local cmd="$(grep '^Exec=' "$1" | cut -d= -f2-)"
  eval " $cmd"
}

win_id=$(get_id)
qube="$(get_qube)"

if [ -z "$qube" ]; then
  qube="dom0";
  colour="";
else
  colour="-sb $(get_colour $win_id)"
fi;

choice=$(scrape_apps "$qube" | sort | wrap_dmenu -p "$qube" $colour $*)
[ -z "$choice" ] && exit

file="$(find_file "$qube" "$choice")"
[ -z "$file" ] && exit

execute_app "$file"