run-recent - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
run-recent (636B)
---
1 #!/bin/sh
2 # end a command with ; to run in a terminal
3
4 term="${TERMINAL:-st} -e"
5 cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
6 cache="$cachedir/dmenu_recent"
7
8 touch "$cache"
9
10 # cleaning
11 while read cmd
12 do
13 command -v ${cmd%;} &>/dev/null || sed -i "/$cmd/d" $cache
14 done < <(sort -u $cache)
15
16 most_used=$(sort "$cache" | uniq -c | sort -rh | sed 's/\s*//' | cut -d' ' -f2-)
17 run=$((echo "$most_used"; dmenu_path | grep -vxF "$most_used") | dmenu -i "$@")
18
19 [ -z "$run" ] && exit 1
20
21 (echo "$run"; head -n 99 "$cache") > "$cache.$$"
22 mv "$cache.$$" "$cache"
23
24 case "$run" in
25 *\;) exec $(echo $term ${run%;}) ;;
26 *) exec "$run" ;;
27 esac
28