[wiki] [sites] [dmenu](run-recent) cache cleaning and optimisation || ananthu

From: <git_AT_suckless.org>
Date: Sat, 09 Oct 2021 11:13:40 +0200

commit 0b7805f55ed530c3328f0b1b9aaaef50607bd62e
Author: ananthu <ask1234560_AT_gmail.com>
Date: Sat Oct 9 14:42:47 2021 +0530

    [dmenu](run-recent) cache cleaning and optimisation

diff --git a/tools.suckless.org/dmenu/scripts/run-recent b/tools.suckless.org/dmenu/scripts/run-recent
index 6d57392d..2cd0c545 100755
--- a/tools.suckless.org/dmenu/scripts/run-recent
+++ b/tools.suckless.org/dmenu/scripts/run-recent
_AT_@ -1,18 +1,28 @@
 #!/bin/sh
 # end a command with ; to run in a terminal
 
-term="st -e"
+term="$TERMINAL -e"
 cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
 cache="$cachedir/dmenu_recent"
 
 touch "$cache"
 
-most_used=$(sort "$cache" | uniq -c | sort -rh | awk -F" " '{print $2}')
+# cleaning
+while read cmd
+do
+ command -v ${cmd%;} &>/dev/null || sed -i "/$cmd/d" $cache
+done < <(sort -u $cache)
+
+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 "$_AT_")
-([ -z "$run" ] || echo "$run"; head -n 99 "$cache") > "$cache.$$"
+
+[ -z "$run" ] && exit 1
+
+(echo "$run"; head -n 99 "$cache") > "$cache.$$"
 mv "$cache.$$" "$cache"
 
 case "$run" in
     *\;) exec $(echo $term ${run%;}) ;;
     *) exec "$run" ;;
 esac
+
Received on Sat Oct 09 2021 - 11:13:40 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 09 2021 - 11:24:45 CEST