From e86f3335854160a031a671cd79653654289f95ff Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 18 Mar 2023 13:56:24 +0530 Subject: menu_run: initial commit: replacement for dmenu_run using only built in sh commands --- menu_run | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 menu_run (limited to 'menu_run') diff --git a/menu_run b/menu_run new file mode 100755 index 0000000..0d5a0c9 --- /dev/null +++ b/menu_run @@ -0,0 +1,47 @@ +#!/bin/sh + +menu="wmenu" +cache_dir="${XDG_CACHE_HOME:-"$HOME/.cache"}" +cache="$cache_dir/wmenu_run" + +uptodate() +{ + IFS=: + for path in $PATH + do + test "$path" -nt "$cache" && + return 1 + done + + return 0 +} + +get_bin() +{ + IFS=: + for path in $PATH + do + for bin in "$path"/* + do + [ -x "$bin" ] && + echo "${bin##*/}" + done + done +} + +main() +{ + [ -d "$cache_dir" ] || + mkdir -p "$cache_dir" + [ -z "$WAYLAND_DISPLAY" ] && + menu="dmenu" + + if [ -f "$cache" ] && uptodate + then + "$menu" "$@" < "$cache" | ${SHELL:-"/bin/sh"} & + else + get_bin | sort -u | tee "$cache" | "$menu" "$@" | ${SHELL:-"/bin/sh"} & + fi +} + +main "$@" -- cgit v1.2.3