We use sort to generate the list of commands ordered by their use count.
---
 dmenu_path | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 dmenu_path

diff --git a/dmenu_path b/dmenu_path
old mode 100644
new mode 100755
index 338bac4..b6f5a9b
--- a/dmenu_path
+++ b/dmenu_path
@@ -1,4 +1,11 @@
 #!/bin/sh
+if [ -z "$1" ]; then
+    echo "Need a history file as first argument."
+    exit
+else
+       HISTORY=$1
+fi
+
 cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
 if [ -d "$cachedir" ]; then
        cache=$cachedir/dmenu_run
@@ -7,7 +14,8 @@ else
 fi
 IFS=:
 if stest -dqr -n "$cache" $PATH; then
-       stest -flx $PATH | sort -u | tee "$cache"
+       stest -flx $PATH | sort -u > "$cache"
+       sort -r -n -t ' ' -k 2 "$HISTORY" | cut -f 1 | cat - "$cache"
 else
-       cat "$cache"
+       sort -r -n -t ' ' -k 2 "$HISTORY" | cut -f 1 | cat - "$cache"
 fi
-- 
2.6.2


Reply via email to