Heyolo

On Sat, Dec 12, 2015 at 06:36:05AM -0800, Xarchus wrote:
> Yes, I feel strongly that if dmenu_path used to keep its file in a standard
> place (XDG_CACHE_HOME or as a dot in HOME), then the history should be
> placed in the same location. It's just clean, uniform design.
> 
> I also realized that all the functionality of dmenu_run with history can
> be kept inside one single file, removing the dependency on dmenu_path.

This version saves some conditionals compared to the earlier version so
I prefer this one.


> Basically merging dmenu_run and dmenu_path together with the history
> stuff into one self-contained shell script: dmenu_run_history.
> 
> And the instructions on the wiki should simply say:
> 
>   dmenu_run_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).


I tested the patch and it works as advertised.

A few comments below.


> diff --git a/dmenu_run_history b/dmenu_run_history
> new file mode 100755
> index 0000000..6ef353d
> --- /dev/null
> +++ b/dmenu_run_history
> @@ -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 ~ 

There is a trailing space at the end of the line above.


> +     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]+\t","")
> +                     print
> +                     x[$0]=1
> +             } 

Trailing space here as well.


> +     } !x[$0]++ ' "$cache" \
> +     | dmenu "$@" \
> +     | awk -v histfile=$historyfile '
> +             BEGIN {
> +                     FS=OFS="\t"
> +                     while ( (getline < histfile) > 0 ) {
> +                             count=$1
> +                             sub("^[0-9]+\t","")
> +                             fname=$0
> +                             history[fname]=count
> +                     }
> +                     close(histfile)
> +             }
> +
> +             {
> +                     history[$0]++
> +                     print
> +             }
> +
> +             END {
> +                     if(!NR) exit
> +                     for (f in history)
> +                             print history[f],f | "sort -t '\t' -k1rn >" 
> histfile
> +             }
> +     ' \
> +     | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done

The rest looks good to me, thanks!

I think it can go on the site like that. I would vote for it superseding
the old history patch which integrated the history functionality in
dmenu's C code and does not apply to tip anymore.


Cheers,

Silvan


Reply via email to