-
Notifications
You must be signed in to change notification settings - Fork 3
/
pboard.njs
executable file
·32 lines (28 loc) · 1.03 KB
/
pboard.njs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
/* pb.js (C) 2013-present SheetJS -- http://sheetjs.com */
var n = "pb";
/* vim: set ts=2 ft=javascript: */
var X = require('../');
var program = require('command'+'er');
program
.version(X.version)
.usage('[options] [mode]')
.option('-m, --mode <mode>', 'use specified mode (default text)')
.option('-l, --list-modes', 'list available modes')
.option('-s, --set', 'read from stdin and set the specified clipboard');
program.on('--help', function() {
console.log(' Support email: dev@sheetjs.com');
});
program.parse(process.argv);
var type = program.mode || program.args[0] || 'text';
if(!X.mytype(type)[0]) throw new Error("Unsupported type " + type);
if(program.listModes) { console.log(X.gettypes().join("\n")); process.exit(0); }
if(program.set) {
var data = "";
process.stdin.on('data', function(d) { data += d; });
process.stdin.on('end', function() { X.set(type, data);});
process.stdin.resume();
} else {
process.stdout.write(String(X.get(type)));
if(process.stdout.isTTY) process.stdout.write("\n");
}