summaryrefslogtreecommitdiff
path: root/qubes-dwm-6.2/scripts/dmenu_cur
blob: fd8f152dd2832acc3ca94a2c391424f0fbe433c0 (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
#!/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 |  grep ':Name=' \
  | sed 's/'"$1"': //' | cut -d= -f2- | sort
}

filter() {
  grep -v "Qube Settings"
}

tidy() {
  sed 's/Rxvt Color Unicode Terminal/urxvt/'
}

untidy() {
  sed 's/urxvt/Rxvt Color Unicode Terminal/'
}

find_file() {
  grep "^Name=.*$2" "$(app_path $1)"/*.desktop | 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" | filter | tidy | sort | wrap_dmenu -p "$qube" $colour $* | untidy)
[ -z "$choice" ] && exit

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

execute_app "$file"