wmenu/wmenu_run
sewn ac25b07338 add wmenu_run script, similar to dmenu_run script
based off the works of sinanmohd, modified to be simpler and better
to read, with shellcheck.

Co-authored-by: sinanmohd <sinan@firemail.cc>
2024-03-17 07:49:14 -04:00

35 lines
524 B
Bash
Executable file

#!/bin/sh
cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
cache="$cachedir/wmenu_run"
[ -d "$cachedir" ] || mkdir -p "$cachedir"
uptodate() {
[ -f "$cache" ] || return 1
IFS=:
for path in $PATH; do
# non-POSIX
test "$path" -nt "$cache" && return 1
done
return 0
}
bins() {
IFS=:
for path in $PATH; do
for bin in "$path"/*; do
[ -x "$bin" ] && echo "${bin##*/}"
done
done
}
path() {
if uptodate; then
cat "$cache"
else
bins | sort -u | tee "$cache"
fi
}
path | wmenu "$@" | ${SHELL:-"/bin/sh"} &