-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.js
40 lines (34 loc) · 905 Bytes
/
list.js
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
var inquirer = require('inquirer'),
open = require('open');
require('colors');
function validNum(length, input) {
return input > 0 && input <= length;
}
module.exports = function(bookmarks, keyword) {
console.log(
bookmarks.length + ' bookmarks matching ' +
keyword.yellow +
(bookmarks.length > 0 ? ':\n'.white : '\n')
);
if (bookmarks.length === 0) return;
for (var i = 0; i < bookmarks.length; i++) {
var b = bookmarks[i];
console.log(
((i+1)+' ').white +
b.get('title').blue.bold + ' ' +
b.get('url').green + '\n ' +
('#' + b.get('tags').join(', #')).grey +
'\n'
);
};
var inqNum = {
name:'num',
message:'Open bookmark number:',
validate: validNum.bind(null, bookmarks.length)
};
inquirer.prompt([inqNum], function(input) {
var bm = bookmarks[input.num-1];
console.log(('Opening ' + bm.get('title') + '...').grey);
open(bm.get('url'));
});
}