Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using growl with a CLI #59

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.log
node_modules
46 changes: 46 additions & 0 deletions bin/growl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

var growl = require('../lib/growl')
, program = require('commander')
, pkg = require('../package.json')
, NEW_LINE = '\n ';

program
.version(pkg.version)
.option('-t --title <title>', 'Notifcation title')
.option('-a --app <name>', 'Application name')
.option('-s --sticky', 'Whether or not the notication should remain until closed')
.option('-i --image <image>', lines(
'Auto-detects the context:'
, '- path to an icon sets --iconpath'
, '- path to an image sets --image'
, '- capitalized word sets --appIcon'
, '- filename uses extname as --icon'
, '- otherwise treated as --icon'
))
.option('-p --priority <priority>', 'Priority for the notification (default is 0)')
.option('-e --exec <command>', lines(
'Manually specify a shell command instead'
, '- appends message to end of shell command'
, '- or, replaces %s with message'
, '- optionally prepends title (example: title: message)'
, '- examples: --exec "tmux display-message" --exec "echo \'%s\' > messages.log"'
))
.arguments('<message>')
.action(notify)
.parse(process.argv);

if (program.args.length < 1) program.help();

function notify(message) {
var options = program.options.reduce(function (options, option) {
var name = option.name();
if (program[name]) options[name] = program[name];
return options;
}, {});
growl(message, options);
}

function lines() {
return Array.prototype.join.call(arguments, NEW_LINE);
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
"url": "git://github.com/tj/node-growl.git"
},
"main": "./lib/growl.js",
"license": "MIT"
"bin": {
"growl": "./bin/growl.js"
},
"license": "MIT",
"dependencies": {
"commander": "^2.9.0"
}
}