[hackers] [dmenu][RFC][PATCH 1/4] Use sort to generate the command list

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Fri, 27 Nov 2015 19:38:29 +0100

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
_AT_@ -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
_AT_@ -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
Received on Fri Nov 27 2015 - 19:38:29 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 27 2015 - 19:48:15 CET