output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / xdg-autostart
blob989ba1ee6388a3d1d36181bbf4d1b491ef550b18
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 xdg-autostart - Start XDG autostart programms
10 =cut
12 EOF
15 shopt -s nullglob
16 declare -A seen
17 declare -A prop
18 DRY=0
21 loadprops()
23 prop=()
24 local IFS=$'\n'
25 for line in `grep -vE '^\s*(#|$)' "$1"`
27 key=${line%%=*}
28 prop[${key,,}]=${line#*=}
29 done
32 ison()
34 local v=${prop[$1]}
35 v=${v,,}
36 test "$v" = true -o "$v" = on -o "$v" = 1 -o "$v" = yes
39 inlist()
41 local needle=$1
42 local glue=$2
43 local haystack=$3
44 local IFS=$glue
45 for x in $haystack
47 if [ "$x" = "$needle" ]
48 then
49 return 0
51 done
52 return 1
55 runwd()
57 if [ -n "${prop[path]}" ]
58 then
60 set -e
61 cd "${prop[path]}"
62 run "$@"
64 else
65 run "$@"
69 run()
71 if [ "$DRY" = 1 ]
72 then
73 echo FILE=$desktop_file EXEC="$@"
74 else
76 exec "$@"
78 disown
84 while [ -n "$1" ]
86 case "$1" in
87 -h|--help)
88 echo "Options:
89 --dry-run, -n Do not run anything, only show"
90 exit
92 -n|--dry-run)
93 DRY=1
96 echo "Unknown option: $1" >&2
97 exit 1
99 esac
100 shift
101 done
105 for desktop_file in $HOME/.config/autostart/*.desktop /etc/xdg/autostart/*.desktop
107 filename=${desktop_file##*/}
108 loadprops "$desktop_file"
110 if [ "${seen[$filename]}" != 1 ]
111 then
112 seen[$filename]=1
114 if ison hidden
115 then
116 continue
118 if [ -n "${prop[notshowin]}" ] && inlist icewm ';' "${prop[notshowin],,}"
119 then
120 continue
122 if [ -n "${prop[onlyshowin]}" ] && ! inlist icewm ';' "${prop[onlyshowin],,}"
123 then
124 continue
126 if [ -n "${prop[tryexec]}" ] && ! type "${prop[tryexec]}" >/dev/null 2>&1
127 then
128 continue
130 if [ "${prop[type],,}" != application ]
131 then
132 continue
136 cmd=${prop[exec]}
138 if ison terminal
139 then
140 cmd="x-terminal-emulator -e $cmd"
143 runwd $cmd
145 done