Sha256: 0d56d335bcf25f5d25324eba0c7177cb6629498c3fdc87e104599c34cf66ef54

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

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

# This is the wrapper around 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!

# BSD guests do not support shared folders
unless RUBY_PLATFORM =~ /freebsd|openbsd|netbsd/
  if options[:i]
    new_filename = options[:i].gsub('/', '-')
    FileUtils.cp options[:i], "<%= shared_folder %>/#{new_filename}"
    options[:i]  = new_filename
  end
end

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

# All single quotes part of the message get removed.
# TODO: Need to escape values.
unless ARGV.empty?
  cmd << ARGV.map{|a| " '#{a.gsub(/'/, "")}'"}.join(' ')
end

# VirtualBox is the only provider that can communicate with 127.0.0.1, others will have to use default private networking
if "<%= provider_name %>" == "virtualbox"
  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
else
  client_ip = "<%= client_ip %>"
end


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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vagrant-notify-0.5.6 files/notify-send.erb
vagrant-notify-0.5.5 files/notify-send.erb
vagrant-notify-0.5.4 files/notify-send.erb
vagrant-notify-0.5.3 files/notify-send.erb
vagrant-notify-0.5.2 files/notify-send.erb