Sha256: 2f1cbabebe7732ab41d5e679c31e4a768ae62590fc5f5762540ef9e489fafa68

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :

# This is the wrapper around Ubuntu's notify-send that connects to the host machine
# when sending notifications

require 'rubygems'
require 'socket'
require 'optparse'
require 'fileutils'

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: notify-send.rb [options]"

  opts.on('-u', '--urgency LEVEL')           { |v| options[:u] = v }
  opts.on('-t', '--expire-time TIME')        { |v| options[:t] = v }
  opts.on('-a', '--app-name APP_NAME')       { |v| options[:a] = v }
  opts.on('-i', '--icon ICON[,ICON...]')     { |v| options[:i] = v }
  opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:c] = v }
  opts.on('-h', '--hint TYPE:NAME:VALUE')    { |v| options[:h] = v }
  opts.on('-v', '--version')                 { |v| options[:v] = v }

end.parse!

if options[:i]
  new_filename = options[:i].gsub('/', '-')
  FileUtils.cp options[:i], "<%= shared_folder %>/#{new_filename}"
  options[:i]  = new_filename
end

cmd = options.map do |key, value|
  "-#{key} '#{value}'"
end.join(' ')

# TODO: Need to escape values
unless ARGV.empty?
  cmd << ARGV.map{|a| " '#{a.gsub(/'/, "")}'"}.join(' ')
end

if RUBY_PLATFORM =~ /linux/
  client_ip = `ip route|awk '/default/ {print $3}'`
elsif RUBY_PLATFORM =~ /solaris|freebsd|openbsd|netbsd/
  client_ip = `netstat -r|awk '/default/ {print $2}'`
end

TCPSocket.open client_ip, <%= host_port %> do |s|
  s.send cmd, 0
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-notify-0.5.1 files/notify-send.erb