Skip to content

Instantly share code, notes, and snippets.

@vivien
Last active December 23, 2023 03:41
Show Gist options
  • Select an option

  • Save vivien/9516784 to your computer and use it in GitHub Desktop.

Select an option

Save vivien/9516784 to your computer and use it in GitHub Desktop.

Revisions

  1. vivien revised this gist Jul 29, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion notify
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,7 @@ URGENCY="$5"
    dunst

    # signal i3blocks that there is a new notification
    killall -USR2 i3blocks
    pkill -RTMIN+12 i3blocks
    exit

    fi
  2. vivien revised this gist Mar 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions notify
    Original file line number Diff line number Diff line change
    @@ -64,13 +64,13 @@ then # called by i3blocks
    else # called by dunst

    # store the notification
    cat <<DUNST > $CACHE
    cat << dunst > $CACHE
    APPNAME="$1"
    SUMMARY="$2"
    BODY="$3"
    ICON="$4"
    URGENCY="$5"
    DUNST
    dunst

    # signal i3blocks that there is a new notification
    killall -USR2 i3blocks
  3. vivien revised this gist Mar 12, 2014. 1 changed file with 7 additions and 14 deletions.
    21 changes: 7 additions & 14 deletions notify
    Original file line number Diff line number Diff line change
    @@ -63,21 +63,14 @@ then # called by i3blocks

    else # called by dunst

    # get the settings
    APPNAME=$1
    SUMMARY=$2
    BODY=$3
    ICON=$4
    URGENCY=$5

    # store the notification
    cat <<NOTIFY > $CACHE
    APPNAME="$APPNAME"
    SUMMARY="$SUMMARY"
    BODY="$BODY"
    ICON="$ICON"
    URGENCY="$URGENCY"
    NOTIFY
    cat <<DUNST > $CACHE
    APPNAME="$1"
    SUMMARY="$2"
    BODY="$3"
    ICON="$4"
    URGENCY="$5"
    DUNST

    # signal i3blocks that there is a new notification
    killall -USR2 i3blocks
  4. vivien created this gist Mar 12, 2014.
    88 changes: 88 additions & 0 deletions notify
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    #!/bin/sh
    #
    # i3blocks integration with dunst.
    # Author: Vivien Didelot <vivien.didelot@gmail.com>
    #
    # dunst caches a notification and signals i3blocks.
    # i3blocks catches the signal and prints the cached notification.
    #
    # Put this rule at the end of your ~/.config/dunst/dunstrc:
    #
    # [i3blocks]
    # summary = "*"
    # script = FULL_PATH_OF_THIS_SCRIPT
    #
    # Add this block in your ~/.i3blocks.conf:
    #
    # [dunst]
    # command=THIS_SCRIPT
    # signal=12

    CACHE=~/.cache/i3blocks/notification

    # Ensure the cache exists
    mkdir -p `dirname $CACHE`
    touch $CACHE

    if env | grep -q BLOCK_
    then # called by i3blocks

    # clear notification on click
    test $BLOCK_BUTTON -ne 0 && cp /dev/null $CACHE

    # source the notification
    . $CACHE

    FULL_TEXT="$SUMMARY $BODY"
    SHORT_TEXT="$SUMMARY"

    case $URGENCY in
    LOW)
    COLOR=#FFFFFF
    CODE=0
    ;;
    NORMAL)
    COLOR=#00FF00
    CODE=0
    ;;
    CRITICAL)
    COLOR=#FF0000
    CODE=33
    ;;
    *)
    # unknown urgency, certainly empty notification
    exit 0
    ;;
    esac

    # Output the status block
    echo $FULL_TEXT
    echo $SHORT_TEXT
    echo $COLOR
    exit $CODE

    else # called by dunst

    # get the settings
    APPNAME=$1
    SUMMARY=$2
    BODY=$3
    ICON=$4
    URGENCY=$5

    # store the notification
    cat <<NOTIFY > $CACHE
    APPNAME="$APPNAME"
    SUMMARY="$SUMMARY"
    BODY="$BODY"
    ICON="$ICON"
    URGENCY="$URGENCY"
    NOTIFY

    # signal i3blocks that there is a new notification
    killall -USR2 i3blocks
    exit

    fi

    # vim: ts=2 sw=2 et