summaryrefslogtreecommitdiff
path: root/dmenu
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-02-09 11:08:35 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-02-09 11:08:35 +0900
commitade72d85ebc04455e6cc7be5ccb53b2890efd18d (patch)
tree79e397527f5349f916e0fef82cf6b9ab1d15a0c7 /dmenu
parentfeb68a52e559ae769150d6971cbd4c0f3038c86e (diff)
modified dmenu/dmenu_path, modified dmenu/dmenu_run
Diffstat (limited to 'dmenu')
-rwxr-xr-xdmenu/dmenu_path21
-rwxr-xr-xdmenu/dmenu_run34
2 files changed, 37 insertions, 18 deletions
diff --git a/dmenu/dmenu_path b/dmenu/dmenu_path
index 9b3b1f2..9e7c801 100755
--- a/dmenu/dmenu_path
+++ b/dmenu/dmenu_path
@@ -1,12 +1,13 @@
#!/bin/sh
-#
-# dmenu_path: Override dmenu_path sorting results by atime.
-#
-# By default, dmenu_path sorts executables alphabetically. It seems to make
-# more sense to sort them by atime in an effort to reduce the number of
-# keystrokes needed to start a program.
-echo $PATH | tr ':' '\n' | uniq | sed 's#$#/#' | # List directories in $PATH
- xargs ls -lu --time-style=+%s | # Add atime epoch
- awk '/^(-|l)/ { print $6, $7 }' | # Only print timestamp and name
- sort -rn | cut -d' ' -f 2
+cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
+cache="$cachedir/dmenu_run"
+
+[ ! -e "$cachedir" ] && mkdir -p "$cachedir"
+
+IFS=:
+if stest -dqr -n "$cache" $PATH; then
+ stest -flx $PATH | sort -u | tee "$cache"
+else
+ cat "$cache"
+fi
diff --git a/dmenu/dmenu_run b/dmenu/dmenu_run
index a9e23b6..c22468b 100755
--- a/dmenu/dmenu_run
+++ b/dmenu/dmenu_run
@@ -1,14 +1,32 @@
#!/bin/sh
+# end a command with ; to run in a terminal
-# dmenu_run improved
-# command ending with '!', is started in the terminal.
+term="${TERMINAL:-st} -e"
+cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
+cache="$cachedir/dmenu_recent"
-test -s "$HOME"/.dmenurc && . "$HOME"/.dmenurc
+touch "$cache"
-cmd="$(dmenu_path | dmenu -H "${XDG_CACHE_HOME:-$HOME/.cache/}/dmenu_run.hist" "$@")"
+# cleaning
+sort -u "$cache" | while read cmd; do
+ command -v "${cmd%;}" >/dev/null 2>&1 || sed -i "/$cmd/d" "$cache"
+done
-case $cmd in
-'') ;;
-*\;) exec "${TERMINAL:-st}" -e ${cmd%?} & ;;
-*) exec ${cmd} & ;;
+most_used=$(sort "$cache" | uniq -c | sort -rh | sed 's/\s*//' | cut -d' ' -f2-)
+run=$( (
+ echo "$most_used"
+ dmenu_path | grep -vxF "$most_used"
+) | dmenu -i "$@")
+
+[ -z "$run" ] && exit 1
+
+(
+ echo "$run"
+ head -n 99 "$cache"
+) >"$cache.$$"
+mv "$cache.$$" "$cache"
+
+case "$run" in
+*\;) exec $(echo $term ${run%;}) ;;
+*) exec "$run" ;;
esac