项目作者: jpco

项目描述 :
A notification server which simply cats its received notifications
高级语言: C
项目地址: git://github.com/jpco/notcat.git
创建时间: 2018-02-22T08:49:10Z
项目社区:https://github.com/jpco/notcat

开源协议:GNU General Public License v3.0

下载


notcat

For when you just want something to print, or run, whenever notifications arrive. Much like statnot, but even simpler (and significantly zippier).

Still a bit rough.

Notcat is built on top of the notlib library.

Downloading && installing

Notcat uses git submodules. To properly clone and build:

  1. git clone https://github.com/jpco/notcat && cd notcat
  2. git submodule init
  3. git submodule update
  4. make (ensure the glib and dbus libraries are installed for notlib)
  5. sudo make install

Running notcat

  1. Usage:
  2. notcat [-h|--help]
  3. notcat [send <opts> | close <id> | getcapabilities | getserverinfo | listen]
  4. notcat [-se] [-t <timeout>] [--capabilities=<cap1>,<cap2>...] \
  5. [--on-notify=<cmd>] [--on-close=<cmd>] [--on-empty=<cmd>] \
  6. [--] [format]...
  7. Options:
  8. --on-notify=<command> Command to run on each notification created (default: echo)
  9. --on-close=<command> Command to run on each notification closed
  10. --on-empty=<command> Command to run when no notifications remain
  11. --capabilities=<cap1>,<cap2>...
  12. Additional capabilities to advertise
  13. -t, --timeout=<timeout>
  14. Default timeout for notifications in milliseconds
  15. -s, --shell Execute subcommands in a subshell
  16. -e, --env Pass notifications to commands in the environment
  17. -h, --help This help text
  18. -- Stop flag parsing

—on-notify, —on-close, —on-empty

Notcat can execute arbitrary subcommands when notifications are received and closed via the --on-notify and --on-close flags, respectively. When the last notification is closed, the --on-empty subcommand is run after --on-close.

Subcommands are invoked one-at-a-time; if an event (a new notification, closed notification, etc.) occurs during the invocation of a subcommand, that event is queued internally.

Format strings

Notcat is configurable via format strings (similar to the standard date command). It accepts any number of format string arguments.

Supported format sequences are:

  1. %% '%'
  2. %i id
  3. %a app name
  4. %s summary
  5. %B body
  6. %e expiration timeout
  7. %u urgency
  8. %c category
  9. %n type of event
  10. %(h:NAME) hint by NAME
  11. %(A:KEY) action by KEY

When the -e flag is not set, format arguments are filled-in and passed 1:1 to executed subcommands. For example, when a notification is sent to notcat executed as

  1. $ notcat --on-notify=/bin/echo %s '%u %B'

notcat will execute the command as follows:

  1. /bin/echo '<summary>' '<urgency> <body>'

On the other hand, if the -s flag is also passed to the above notcat invocation, it will execute the command as:

  1. $SHELL -c /bin/echo notcat '<summary>' '<urgency> <body>'

In this case, the subcommand isn’t very useful (simply echoing an empty line each time). Figuring out how shells’ -c flag works is left as an exercise for the reader. (The ‘notcat’ in the above is hard-coded, setting the $0 of the executed subshell.)

Format conditionals

Notcat can key off of the presence (and non-defaultness) of certain notification fields without having to print them, using format conditional syntax, illustrated here:

  1. $ notcat '%s%(?B: - )%B'

When notcat, invoked with this format argument, receives a notification with a body, it will display summary - body. When it receives a notification with no body, it will simply display summary.

Environment variables

When the -e flag is set, notcat will not pass its format flags to its commands, instead setting a number of environment variables which the commands can use. This may be more convenient for people who write scripts to be executed by notcat.

Environment variables currently sent to commands when the -e flag is set are:

  1. NOTE_ID
  2. NOTE_APP_NAME
  3. NOTE_SUMMARY
  4. NOTE_BODY
  5. NOTE_URGENCY
  6. NOTE_TIMEOUT

Actions and generic hints are not yet supported in environment variables.

Example usage:

  1. $ cat ./post.sh
  2. #!/bin/sh
  3. cat <<EOF
  4. received notification $NOTE_ID from $NOTE_APP_NAME:
  5. $NOTE_SUMMARY
  6. $NOTE_BODY
  7. EOF
  8. $ notcat -e --on-notify=./post.sh

Client commands

notcat can also be used to interact as a client with an already-running notification server. Existing commands are:

  • close <ID>: Close the notification with the given ID.

  • invoke <ID> <KEY>: Invoke the action with the given key on the notification with the given ID. Will not work with just about any notification server other than notcat.

  • getcapabilities: Get the capabilities of the notification server.

  • getserverinfo: Get basic information about the notification server.

  • send: Send a notification to the server.

  • listen: Listen for signals from the server, and print a message for each one received.

TODO

  • more format sequences and environment variables
    • catch up environment variables to format sequences (actions and hints!)
  • markup “support”, as far as it will go
    • [b], [i], [u], [a href], [img src alt] is all you need
    • starting with stripping all markup (and advertising ‘body-markup’)
    • then allow flags to format markup
  • D-Bus error reporting