Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

56 lines
1.1 KiB

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