Skip to content

Commit

Permalink
Add --copy flag
Browse files Browse the repository at this point in the history
Fixes part of sindresorhus#2

Closes sindresorhus#15
  • Loading branch information
sindresorhus committed Dec 5, 2016
1 parent 80e8db6 commit 65e5bc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
22 changes: 18 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const chalk = require('chalk');
const debounce = require('lodash.debounce');
const hasAnsi = require('has-ansi');
const mem = require('mem');
const clipboardy = require('clipboardy');
const emoj = require('./');

// limit it to 7 results so not to overwhelm the user
// this also reduces the chance of showing unrelated emojis
const fetch = mem(str => emoj(str).then(arr => arr.slice(0, 7).join(' ')));
const fetch = mem(str => emoj(str).then(arr => arr.slice(0, 7)));

const debouncer = debounce(cb => cb(), 200);

Expand All @@ -24,11 +25,24 @@ const cli = meow(`
$ emoj 'i love unicorns'
🦄 🎠 🐴 🐎 ❤ ✨ 🌈
Options
--copy -c Copy the first emoji to the clipboard
Run it without arguments to enter the live search
`);
`, {
boolean: [
'copy'
],
alias: {
c: 'copy'
}
});

if (cli.input.length > 0) {
fetch(cli.input[0]).then(console.log);
fetch(cli.input[0]).then(val => {
console.log(val.join(' '));
clipboardy.writeSync(val[0]);
});
return;
}

Expand Down Expand Up @@ -88,7 +102,7 @@ process.stdin.on('keypress', (ch, key) => {
return;
}

prevResult = emojis;
prevResult = emojis = emojis.join(' ');
logUpdate(`${pre}${chalk.bold(query.join(''))}\n${emojis}\n`);
});
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
],
"dependencies": {
"chalk": "^1.1.3",
"clipboardy": "^0.1.1",
"got": "^6.3.0",
"has-ansi": "^2.0.0",
"lodash.debounce": "^4.0.6",
Expand All @@ -45,6 +46,6 @@
},
"devDependencies": {
"ava": "*",
"xo": "*"
"xo": "^0.16.0"
}
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ $ emoj --help
$ emoj 'i love unicorns'
🦄 🎠 🐴 🐎 ❤ ✨ 🌈
Options
--copy -c Copy the first emoji to the clipboard
Run it without arguments to enter the live search
```

Expand Down

0 comments on commit 65e5bc4

Please sign in to comment.