dmenu_run_hlwm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. if ! command -v dmenu > /dev/null 2>/dev/null ; then
  3. echo "Error: Requirement dmenu not found in your PATH." >&2
  4. exit 1
  5. fi
  6. # Get the currently active tag
  7. tag=$(herbstclient attr tags.focus.name)
  8. # Redirect to dmenu_path if available
  9. if command -v dmenu_path > /dev/null 2>/dev/null ; then
  10. selectedPath=$(dmenu_path | dmenu "$@")
  11. # If at least stest is present use the code from latest dmenu_path directly
  12. elif command -v stest > /dev/null 2>/dev/null ; then
  13. cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
  14. if [ -d "$cachedir" ]; then
  15. cache=$cachedir/dmenu_run
  16. else
  17. cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
  18. fi
  19. IFS=:
  20. if stest -dqr -n "$cache" $PATH; then
  21. selectedPath=$(stest -flx $PATH | sort -u | tee "$cache" | dmenu "$@")
  22. else
  23. selectedPath=$(dmenu "$@" < "$cache")
  24. fi
  25. # Both not found -> unable to continue
  26. else
  27. echo "Error: Requirements dmenu_path or stest not found in your PATH." >&2
  28. exit 2
  29. fi
  30. # Stop here if the user aborted
  31. [ -z $selectedPath ] && exit 0
  32. # Move next window from this process to this tag. Prepend the rule so
  33. # that it may be overwritten by existing custom rules e.g. in the
  34. # autostart. Also set a maximum age for this rule of 120 seconds and
  35. # mark it as one-time-only rule.
  36. herbstclient rule prepend maxage="120" pid="$$" tag="$tag" once
  37. exec $selectedPath