/
nwm
executable file
·54 lines (47 loc) · 1.6 KB
/
nwm
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
which = require('which');
var opts = require('yargs')
.boolean('init')
.boolean('version'),
argv = opts.parse(process.argv);
if (argv['version'] || argv['v']) {
console.log(require('../package.json').version);
process.exit();
}
if (argv['help']) {
return fs.createReadStream(__dirname + '/usage.txt')
.pipe(process.stdout)
.on('close', function() { process.exit(1) });
}
if (argv['init']) {
which('nwm', function(err, filepath) {
if (err || !filepath) {
console.log('Could not find the nwm command using `which`.');
console.log('Please create a file named `/usr/share/xsessions/nwm.desktop` ' +
'with the following content, and ' +
'fill in the correct path `:path-to-nwm` manually.');
console.log('This may happen if you didn\'t install nwm with `npm install -g nwm`');
console.log();
console.log(fs.readFileSync(__dirname + '/nwm.desktop', 'utf8'));
return;
}
var out = fs.readFileSync(__dirname + '/nwm.desktop', 'utf8')
.replace(':path-to-nwm', filepath)
console.log(out);
});
return;
}
var homePath = process.env['HOME'];
homePath = (typeof homePath === 'string' ? path.normalize(homePath) : process.cwd());
// try ~/.nwm-user
try {
require(homePath + '/.nwm-user')(require('../index.js'));
return;
} catch (e) {
console.log('Error finding or executing ~/.nwm-user, launching with default nwm-user-sample.js');
console.log('Error was:');
console.log(e);
}
require('../nwm-user-sample.js')(require('../index.js'));