Changed dmenu_path (fixed race, improved speed, check that $PATH is the same as the last run). c04b688c
Kris Maglione · 2007-05-23 16:42 1 file(s) · +17 −16
dmenu_path +17 −16
1 -
#!/bin/sh
1 +
#!/bin/sh -f
2 2
CACHE=$HOME/.dmenu_cache
3 3
IFS=:
4 4
5 +
qfind() {
6 +
	find "$@" 2>/dev/null
7 +
}
8 +
5 9
uptodate() {                                                                       
6 -
	test ! -f $CACHE && return 1                                                   
7 -
	for dir in $PATH                                                                
8 -
	do                                                                              
9 -
		test $dir -nt $CACHE && return 1                                           
10 -
	done                                                                            
11 -
	return 0                                                                       
12 -
}          
10 +
	test -f $CACHE &&
11 +
		test "$(echo "$PATH")" = "$(sed 1q "$CACHE")" &&
12 +
		qfind $PATH -maxdepth 0 -newer $CACHE
13 +
}
13 14
14 15
if ! uptodate
15 16
then
16 -
	for dir in $PATH
17 -
	do
18 -
		for file in "$dir"/*
19 -
		do
20 -
			test -x "$file" && echo "${file##*/}"
21 -
		done
22 -
	done | sort | uniq > $CACHE
17 +
	{
18 +
		echo "$PATH"
19 +
		qfind $PATH -type f -maxdepth 1 -perm -u+x -o -perm -g+x -o -perm -o+x |
20 +
			sed 's,.*/,,' | sort | uniq
21 +
	} > $CACHE.$pid
22 +
	mv $CACHE.$pid $CACHE
23 23
fi
24 24
25 -
cat $CACHE
25 +
tail -n +2 $CACHE
26 +