Module: Guard::Notifier::NotifySend

Extended by:
NotifySend
Included in:
NotifySend
Defined in:
lib/guard/notifiers/notifysend.rb

Overview

System notifications using notify-send, a binary that ships with the libnotify-bin package on many Debian-based distributions.

Examples:

Add the `:notifysend` notifier to your `Guardfile`

notification :notifysend

Constant Summary

DEFAULTS =

Default options for the notify-send program

{
  :t => 3000 # Default timeout is 3000ms
}
SUPPORTED =

Full list of options supported by notify-send

[:u, :t, :i, :c, :h]

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) available?(silent = false)

Test if the notification program is available.

Parameters:

  • silent (Boolean) (defaults to: false)

    true if no error messages should be shown

Returns:

  • (Boolean)

    the availability status



28
29
30
31
32
33
34
35
# File 'lib/guard/notifiers/notifysend.rb', line 28

def available?(silent = false)
  if (RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/) and (not `which notify-send`.empty?)
    true
  else
    ::Guard::UI.error 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' unless silent
    false
  end
end

- (Object) notify(type, title, message, image, options = { })

Show a system notification.

Parameters:

  • type (String)

    the notification type. Either 'success', 'pending', 'failed' or 'notify'

  • title (String)

    the notification title

  • message (String)

    the notification message body

  • image (String)

    the path to the notification image

  • options (Hash) (defaults to: { })

    additional notification library options

Options Hash (options):

  • c (String)

    the notification category

  • t (Number)

    the number of milliseconds to display (1000, 3000)



47
48
49
50
51
52
53
54
# File 'lib/guard/notifiers/notifysend.rb', line 47

def notify(type, title, message, image, options = { })
  command = "notify-send '#{title}' '#{message}'"
  options = DEFAULTS.merge(options).merge({
    :i => image
  })
  options[:u] ||= notifysend_urgency(type)
  system(to_command_string(command, SUPPORTED, options))
end