commit 0b7805f55ed530c3328f0b1b9aaaef50607bd62e
Author: ananthu <[email protected]>
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
@@ -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 "$@")
-([ -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
+