notif 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # Uncomment the following line to get debug info
  3. #set -x
  4. SELF="$(basename ${0})"
  5. NOTIFICATION_DISPLAY=/sys/class/graphics/fb0/notification
  6. usage() {
  7. >&2 echo "Usage: ${SELF} set duration message"
  8. >&2 echo " ${SELF} display duration message"
  9. >&2 echo " ${SELF} clear"
  10. exit 1
  11. }
  12. notif_clear() {
  13. echo -n "clear" > "${NOTIFICATION_DISPLAY}"
  14. }
  15. notif_display() {
  16. local duration="${1}"
  17. local message="${*:2}"
  18. if ! [ ! "${duration}" -ne "${duration}" ] 2> /dev/null; then
  19. >&2 echo "error: ${duration} is not a number"
  20. exit 3
  21. fi
  22. echo -n "${message}" > "${NOTIFICATION_DISPLAY}"
  23. if [ ${duration} -ne 0 ]; then
  24. sleep ${duration}
  25. notif_clear
  26. fi
  27. }
  28. notif_set() {
  29. local duration="${1}"
  30. local message="${*:2}"
  31. if ! [ ! "${duration}" -ne "${duration}" ]; then
  32. >&2 echo "error: ${duration} is not a number"
  33. exit 2
  34. fi
  35. # Kill previous notif disp process
  36. pkill -f "notif display" 2> /dev/null
  37. # Print new notif
  38. notif display "${duration}" "${message}" &
  39. }
  40. case "${1}" in
  41. set)
  42. if [ ${#} -ne 3 ]; then
  43. usage
  44. fi
  45. shift
  46. notif_set "${1}" "${2}"
  47. ;;
  48. clear)
  49. if [ ${#} -ne 1 ]; then
  50. usage
  51. fi
  52. notif_clear
  53. ;;
  54. display)
  55. if [ ${#} -ne 3 ]; then
  56. usage
  57. fi
  58. shift
  59. notif_display "${1}" "${2}"
  60. ;;
  61. *)
  62. usage
  63. ;;
  64. esac
  65. exit 0