add wmenu_run script, similar to dmenu_run script - wmenu - 🔧 fork of wmenu
(HTM) git clone git@git.drkhsh.at/wmenu.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ac25b0733885b545578092c5da74c9a3122529d6
(DIR) parent 9e9284666c9fcf3278ad17f98a247658db8b2269
(HTM) Author: sewn <sewn@disroot.org>
Date: Sun, 10 Mar 2024 18:07:46 +0300
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>
Diffstat:
M meson.build | 2 ++
A wmenu_run | 35 +++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/meson.build b/meson.build
@@ -33,6 +33,8 @@ rt = cc.find_library('rt')
subdir('protocols')
subdir('docs')
+install_data('wmenu_run', install_dir: get_option('bindir'))
+
executable(
'wmenu',
files(
(DIR) diff --git a/wmenu_run b/wmenu_run
@@ -0,0 +1,35 @@
+#!/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"} &