I agree with the race fix of JG, but I dislike the SUSV3-breaking find, and I don't care about PATH changes, keep it simple, stupid
3a9f3a51
1 file(s) · +17 −17
| 1 | - | #!/bin/sh -f |
|
| 1 | + | #!/bin/sh |
|
| 2 | 2 | CACHE=$HOME/.dmenu_cache |
|
| 3 | 3 | IFS=: |
|
| 4 | 4 | ||
| 5 | - | qfind() { |
|
| 6 | - | find "$@" 2>/dev/null |
|
| 7 | - | } |
|
| 8 | - | ||
| 9 | - | uptodate() { |
|
| 10 | - | test -f $CACHE && |
|
| 11 | - | test "$(echo "$PATH")" = "$(sed 1q "$CACHE")" && |
|
| 12 | - | ! qfind $PATH -maxdepth 0 -newer $CACHE >/dev/null |
|
| 5 | + | 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 |
|
| 13 | 12 | } |
|
| 14 | 13 | ||
| 15 | 14 | if ! uptodate |
|
| 16 | 15 | then |
|
| 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 | - | } |
|
| 22 | - | mv $CACHE.$pid $CACHE |
|
| 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.$$ |
|
| 23 | + | mv $CACHE.$$ $CACHE |
|
| 23 | 24 | fi |
|
| 24 | 25 | ||
| 25 | - | tail -n +2 $CACHE |
|
| 26 | - | ||
| 26 | + | cat $CACHE |