Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
933 B

  1. #!/bin/sh
  2. cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
  3. if [ -d "$cachedir" ]; then
  4. cache=$cachedir/dmenu_run
  5. historyfile=$cachedir/dmenu_history
  6. else # if no xdg dir, fall back to dotfiles in ~
  7. cache=$HOME/.dmenu_cache
  8. historyfile=$HOME/.dmenu_history
  9. fi
  10. IFS=:
  11. if stest -dqr -n "$cache" $PATH; then
  12. stest -flx $PATH | sort -u > "$cache"
  13. fi
  14. unset IFS
  15. awk -v histfile=$historyfile '
  16. BEGIN {
  17. while( (getline < histfile) > 0 ) {
  18. sub("^[0-9]+\t","")
  19. print
  20. x[$0]=1
  21. }
  22. } !x[$0]++ ' "$cache" \
  23. | dmenu "$@" \
  24. | awk -v histfile=$historyfile '
  25. BEGIN {
  26. FS=OFS="\t"
  27. while ( (getline < histfile) > 0 ) {
  28. count=$1
  29. sub("^[0-9]+\t","")
  30. fname=$0
  31. history[fname]=count
  32. }
  33. close(histfile)
  34. }
  35. {
  36. history[$0]++
  37. print
  38. }
  39. END {
  40. if(!NR) exit
  41. for (f in history)
  42. print history[f],f | "sort -t '\t' -k1rn >" histfile
  43. }
  44. ' \
  45. | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done