diff --git a/dmenu_path b/dmenu_path old mode 100644 new mode 100755 index 338bac4..f16f562 --- a/dmenu_path +++ b/dmenu_path @@ -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 @@ -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" + awk -F$'\t' '!x[$1]++' "$HISTORY" "$cache" else - cat "$cache" + awk -F$'\t' '!x[$1]++' "$HISTORY" "$cache" fi diff --git a/dmenu_run b/dmenu_run index 834ede5..051a2c4 100755 --- a/dmenu_run +++ b/dmenu_run @@ -1,2 +1,5 @@ #!/bin/sh -dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} & + +historyfile=~/.cache/dmenu/dmenuhistory + +dmenu_path $historyfile | dmenu "$@" | awk -v histfile=$historyfile -f updhist.awk | ${SHELL:-"/bin/sh"} & diff --git a/updhist.awk b/updhist.awk index e69de29..76820bf 100755 --- a/updhist.awk +++ b/updhist.awk @@ -0,0 +1,23 @@ +#!/usr/bin/awk -f + +BEGIN { + if(histfile=="") { + print "updhist.awk: no history file specified" > "/dev/stderr" + print "usage: awk -v histfile= -f updhist.awk" > "/dev/stderr" + exit(1) + } + FS=OFS="\t" # explicit tabs on input to allow file names with spaces + while ( (getline < histfile) > 0 ) + history[$1]=$2 # assumption: file name does not contain tabs + close(histfile) +} + +{ + history[$0]++ + print +} + +END { + for (f in history) + print f,history[f] | "sort -t '\t' -k2rn >" histfile +}