sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 0b7805f55ed530c3328f0b1b9aaaef50607bd62e
parent 68804dc901cc1fe130ae8e5bdd28a622489d3197
Author: ananthu <ask1234560@gmail.com>
Date:   Sat,  9 Oct 2021 14:42:47 +0530

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

Diffstat:
Mtools.suckless.org/dmenu/scripts/run-recent | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git 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 +