Heyho! On Sat, Nov 28, 2015 at 11:25 PM, Hiltjo Posthuma <hil...@codemadness.org> wrote: > On Fri, Nov 27, 2015 at 7:38 PM, Silvan Jegen <s.je...@gmail.com> wrote: >> Heyhey >> >> I kept thinking about a more general way to implement history >> functionality for dmenu and this is what I came up with. >> >> We use the sort command to generate an input list for dmenu sorted by >> count (first patch). dmenu itself is not modified and shows the available >> commands with the most often used ones first (due to the sorting done >> by sort). Before sending the dmenu output to a shell we use a simple >> C program that reads a command from stdin for which it increments the >> usage count in the history file before sending the command to the shell >> to execute (patch 4; rest of the patches are just glue code). >> > > This can be implemented in a few lines of shell (wc, sort) and maybe awk.
I *have* implemented the history part with sort. If you think the history updating functionality that I ended up writing in C can be (easily?) implemented in some shell script and/or awk then I would like to see it on the list :) I thought it should be possible to implement in awk but because you have to both read input from stdin (the command) and from a file (the history file) I couldn't figure it out in the admittedly short time I kept trying to do it. I tried abusing the -v option of gawk to set the command name as a variable value but that only seems to work in a BEGIN block which is executed before the input file is read. It may be possible to use the shell to read the command and then initialize a variable in the awk code given on the command line but I think the argument-escaping hell would be very annoying to deal with. >> * It uses the -t and -k options of sort which are not available for >> all sort implementations (not in sbase for example). If there is an >> easy way to replicate this functionality without using these sort >> options I would like to hear about it. > > Sbase sort supports -t and -k, if some part of it is broken: send a patch. You are right. I must have checked an old sbase version. I will test the patch with sbase sort as soon as I find the time. Cheers, Silvan