-#!/bin/sh
+#!/bin/sh -f
+CACHE=$HOME/.dmenu_cache
IFS=:
-for dir in $PATH
-do
- for file in "$dir"/*
- do
- test -x "$file" && echo "${file##*/}"
- done
-done | sort | uniq
+
+qfind() {
+ find "$@" 2>/dev/null
+}
+
+uptodate() {
+ test -f $CACHE &&
+ test "$(echo "$PATH")" = "$(sed 1q "$CACHE")" &&
+ ! qfind $PATH -maxdepth 0 -newer $CACHE >/dev/null
+}
+
+if ! uptodate
+then
+ {
+ echo "$PATH"
+ qfind $PATH -type f -maxdepth 1 '(' -perm -u+x -o -perm -g+x -o -perm -o+x ')' |
+ sed 's,.*/,,' | sort | uniq
+ }
+ mv $CACHE.$pid $CACHE
+fi
+
+tail -n +2 $CACHE
+