Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # i3blocks integration with dunst.
  4. # Author: Vivien Didelot <vivien.didelot@gmail.com>
  5. #
  6. # dunst caches a notification and signals i3blocks.
  7. # i3blocks catches the signal and prints the cached notification.
  8. #
  9. # Put this rule at the end of your ~/.config/dunst/dunstrc:
  10. #
  11. # [i3blocks]
  12. # summary = "*"
  13. # script = FULL_PATH_OF_THIS_SCRIPT
  14. #
  15. # Add this block in your ~/.i3blocks.conf:
  16. #
  17. # [dunst]
  18. # command=THIS_SCRIPT
  19. # signal=12
  20.  
  21. CACHE=~/.cache/i3blocks/notification
  22. NOTIFY_TIMEOUT=30
  23.  
  24. # Ensure the cache exists
  25. mkdir -p `dirname $CACHE`
  26. touch $CACHE
  27.  
  28.  
  29. function clear_notification(){
  30. cp /dev/null $CACHE
  31. . $CACHE
  32. pkill -RTMIN+12 i3blocks
  33. exit
  34. }
  35.  
  36.  
  37. if env | grep -q BLOCK_
  38. then # called by i3blocks
  39.  
  40. # clear notification on click
  41. test $BLOCK_BUTTON -ne 0 && cp /dev/null $CACHE
  42.  
  43. # source the notification
  44. . $CACHE
  45.  
  46. FULL_TEXT="$SUMMARY $BODY"
  47. SHORT_TEXT="$SUMMARY"
  48.  
  49. case $URGENCY in
  50. LOW)
  51. COLOR=#FFFFFF
  52. CODE=0
  53. ;;
  54. NORMAL)
  55. COLOR=#00FF00
  56. CODE=0
  57. ;;
  58. CRITICAL)
  59. COLOR=#FF0000
  60. CODE=33
  61. ;;
  62. *)
  63. # unknown urgency, certainly empty notification
  64. exit 0
  65. ;;
  66. esac
  67.  
  68. # Output the status block
  69. echo $FULL_TEXT
  70. echo $SHORT_TEXT
  71. echo $COLOR
  72. exit $CODE
  73.  
  74. else # called by dunst
  75.  
  76. # store the notification
  77. cat << dunst > $CACHE
  78. APPNAME="$1"
  79. SUMMARY="$2"
  80. BODY="$3"
  81. ICON="$4"
  82. URGENCY="$5"
  83. dunst
  84.  
  85. # signal i3blocks that there is a new notification
  86. pkill -RTMIN+12 i3blocks
  87. exit
  88.  
  89. fi
  90.  
  91. sleep $NOTIFY_TIMEOUT
  92. clear_notification
  93.  
  94. # vim: ts=2 sw=2 et
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement