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.

52 lines
1.2 KiB

  1. #!/usr/bin/env bash
  2. : "${CM_DIR:="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
  3. if [[ -z $1 ]] || [[ $1 == --help ]] || [[ $1 == -h ]]; then
  4. cat << 'EOF'
  5. clipctl provides controls for the clipmenud daemon.
  6. Commands:
  7. enable: enable clip collection
  8. disable: disable clip collection
  9. status: returns "enabled" or "disabled"
  10. toggle: toggles clip collection
  11. version: returns major version
  12. cache-dir: returns the directory used for caching
  13. EOF
  14. exit 0
  15. fi
  16. clipmenud_pid=$(pgrep -u "$(id -u)" -nf 'clipmenud$')
  17. case $1 in
  18. enable|disable|toggle|status)
  19. if [[ -z "$clipmenud_pid" ]]; then
  20. echo "clipmenud is not running" >&2
  21. exit 2
  22. fi
  23. ;;
  24. esac
  25. major_version=6
  26. cache_dir=$CM_DIR/clipmenu.$major_version.$USER
  27. status_file=$cache_dir/status
  28. case $1 in
  29. enable) kill -USR2 "$clipmenud_pid" ;;
  30. disable) kill -USR1 "$clipmenud_pid" ;;
  31. status) cat "$status_file" ;;
  32. toggle)
  33. if [[ $(clipctl status) == "enabled" ]]; then
  34. clipctl disable
  35. else
  36. clipctl enable
  37. fi
  38. ;;
  39. version) echo "$major_version" ;;
  40. cache-dir) echo "$cache_dir" ;;
  41. *)
  42. printf 'Unknown command: %s\n' "$1" >&2
  43. exit 1
  44. ;;
  45. esac