commit d9a44a5fd379d23969f0e666041f1a5a976f05a2
Author: Xarchus <xarchus_AT_comcast.net>
Date: Tue Jan 19 04:25:48 2016 -0800
Alternative to dmenu_run adding command history
- drop-in replacement for dmenu_run, no dmenu patching necessary
- when doing multiselect, runs command immediately upon selection
- added note to the current 'history' patch pointing to this
diff --git a/tools.suckless.org/dmenu/patches/history.md b/tools.suckless.org/dmenu/patches/history.md
index 65b5c2d..b975d04 100644
--- a/tools.suckless.org/dmenu/patches/history.md
+++ b/tools.suckless.org/dmenu/patches/history.md
_AT_@ -22,3 +22,11 @@ Author
------
* Peter John Hartman (wart_) <[
http://antiopus.trilidun.org/durandus/](
http://antiopus.trilidun.org/durandus/)>
+
+Note
+----
+
+As an alternative to the patch above, the following script is meant to replace
+`dmenu_run` : it handles the command history in a similar way as the patch and
+can be used with an unpatched dmenu 4.6.
+[dmenu_run_history](
http://tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history)
diff --git a/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/dmenu_run_history b/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/dmenu_run_history
new file mode 100755
index 0000000..8d436ca
--- /dev/null
+++ b/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/dmenu_run_history
_AT_@ -0,0 +1,50 @@
+#!/bin/sh
+
+cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
+if [ -d "$cachedir" ]; then
+ cache=$cachedir/dmenu_run
+ historyfile=$cachedir/dmenu_history
+else # if no xdg dir, fall back to dotfiles in ~
+ cache=$HOME/.dmenu_cache
+ historyfile=$HOME/.dmenu_history
+fi
+
+IFS=:
+if stest -dqr -n "$cache" $PATH; then
+ stest -flx $PATH | sort -u > "$cache"
+fi
+unset IFS
+
+awk -v histfile=$historyfile '
+ BEGIN {
+ while( (getline < histfile) > 0 ) {
+ sub("^[0-9]+ ","")
+ print
+ x[$0]=1
+ }
+ } !x[$0]++ ' "$cache" \
+ | dmenu "$_AT_" \
+ | awk -v histfile=$historyfile '
+ BEGIN {
+ FS=OFS=" "
+ while ( (getline < histfile) > 0 ) {
+ count=$1
+ sub("^[0-9]+ ","")
+ fname=$0
+ history[fname]=count
+ }
+ close(histfile)
+ }
+
+ {
+ history[$0]++
+ print
+ }
+
+ END {
+ if(!NR) exit
+ for (f in history)
+ print history[f],f | "sort -t ' ' -k1rn >" histfile
+ }
+ ' \
+ | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done
diff --git a/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/index.md b/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/index.md
new file mode 100644
index 0000000..608ae5b
--- /dev/null
+++ b/tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history/index.md
_AT_@ -0,0 +1,23 @@
+dmenu_run with command history
+==============================
+
+A self-contained alternative to dmenu_run which also handles history.
+
+History is saved in a file in `$XDG_CACHE_HOME`, with fallback to a dot
+file in `$HOME`. Change as necessary.
+
+In addition to the above, dmenu_run_history will launch each entry
+immediately on `Ctrl-Return` (multiselect).
+
+The script can be used with the 4.6 version of dmenu.
+
+Download
+========
+
+[dmenu_run_history](dmenu_run_history) (20151217)
+
+Authors
+=======
+
+* Xarchus
+* Silvan Jegen (initial idea, code contributor, feedback)
diff --git a/tools.suckless.org/dmenu/scripts/index.md b/tools.suckless.org/dmenu/scripts/index.md
index cc7dae0..b199ba4 100644
--- a/tools.suckless.org/dmenu/scripts/index.md
+++ b/tools.suckless.org/dmenu/scripts/index.md
_AT_@ -22,3 +22,5 @@ Download
the terminal.
* [browse](
https://github.com/clamiax/scripts/blob/master/src/browse):
little files navigator
+* [dmenu_run_history](
http://tools.suckless.org/dmenu/scripts/dmenu_run_with_command_history) :
+ dmenu_run alternative with command history
Received on Tue Jan 19 2016 - 13:37:02 CET