diff --git a/dmenu_path b/dmenu_path old mode 100644 new mode 100755 index 338bac4..c928173 --- a/dmenu_path +++ b/dmenu_path @@ -1,4 +1,6 @@ #!/bin/sh +HISTORY="$1" + cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"} if [ -d "$cachedir" ]; then cache=$cachedir/dmenu_run @@ -7,7 +9,6 @@ else fi IFS=: if stest -dqr -n "$cache" $PATH; then - stest -flx $PATH | sort -u | tee "$cache" -else - cat "$cache" + stest -flx $PATH | sort -u > "$cache" fi +awk '!cache { sub("^[0-9]+\t","") } !x[$0]++' "$HISTORY" cache=1 "$cache" diff --git a/dmenu_run b/dmenu_run index 834ede5..ef7c579 100755 --- a/dmenu_run +++ b/dmenu_run @@ -1,2 +1,31 @@ #!/bin/sh -dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} & + +historyfile=~/.cache/dmenu/history +if [ ! -e $historyfile ]; then + touch $historyfile +fi + +dmenu_path $historyfile | 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 { + for (f in history) + print history[f],f | "sort -t '\t' -k1rn >" histfile + } + ' \ + | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done