aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/sway/.local/bin/wmenu-run
blob: 2cda132a394221b99f049750591f9aa7c6eb217c (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
#!/bin/sh

cache_dir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
cache="$cache_dir/wmenu_run"

uptodate() {
	IFS=:
	for path in $PATH; do
		if test "$path" -nt "$cache"; then
			return 1
		fi
	done

	return 0
}

get_bin() {
	IFS=:
	for path in $PATH; do
		for bin in "$path"/*; do
			if [ -x "$bin" ]; then
				echo "${bin##*/}"
			fi
		done
	done
}

[ ! -e "$cache_dir" ] && mkdir -p "$cache_dir"

if [ ! -e "$cache" ] || ! uptodate; then
	get_bin | sort -u | tee "$cache"
else
	cat "$cache"
fi