aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-03-18 13:56:24 +0530
committersinanmohd <sinan@firemail.cc>2023-03-18 13:57:20 +0530
commite86f3335854160a031a671cd79653654289f95ff (patch)
treef388dc8d3f867a5ab5c25e802587167f75eb2514
parent3d6a9d7c94a8562ae22d41147379d72cb269c110 (diff)
menu_run: initial commit: replacement for dmenu_run
using only built in sh commands
-rw-r--r--README.md10
-rwxr-xr-xmenu_run47
2 files changed, 57 insertions, 0 deletions
diff --git a/README.md b/README.md
index b285eff..78c4d9c 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,16 @@ scraper for yts.mx, has an optional dependency on pirowatch. if you pass "-o"
as the first argument it'll print the scraped torrent link to stdout otherwise
it will pass the link to pirowatch
+## menu_run
+this scripts does the same job as the dmenu_run script, they why use it?
+dmenu_run depends on stest, they will not be available if you're not
+running xorg and don't have dmenu installed. menu_run only uses built in sh
+commands but if the cache is not prepared dmenu_run will run about
+1.16 +- 0.04 faster than the mentioned script, if it is then menu_run
+will run 2.54 +- 0.26 faster than dmenu_run, which will be the most likely
+situation . though the scale of the gains are very small the main goal
+of the script is to get rid of dependence on stest and dmenu
+
## vpn
dmenu wrapper for wireguard, has an optional dependency on wip. you can pass
wireguard config name as the first argument otherwise it will use the default
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 "$@"