├── .gitignore ├── History.md ├── Makefile ├── Readme.md ├── example.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.1.0 / 2015-10-16 3 | ================== 4 | 5 | * Support FreeBSD 6 | * Fix for linux: populate the clipboard with xclip 7 | 8 | 1.0.1 / 2013-09-12 9 | ================== 10 | 11 | * No new line on echo 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | test: 3 | @./node_modules/.bin/mocha \ 4 | --reporter dot \ 5 | --bail 6 | 7 | .PHONY: test -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Cliparoo 3 | 4 | Sorry for the stupid name. Copies strings to the clipboard, for CLIs. 5 | 6 | ## Installation 7 | 8 | ``` 9 | $ npm install cliparoo 10 | ``` 11 | 12 | ## Example 13 | 14 | ```js 15 | var clip = require('cliparoo'); 16 | 17 | clip('Hello "World"', function(err){ 18 | if (err) throw err; 19 | console.log('copied!'); 20 | }); 21 | ``` -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | 2 | var clip = require('./'); 3 | 4 | clip('Hello "World"', function(err){ 5 | if (err) throw err; 6 | console.log('copied!'); 7 | }); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var exec = require('child_process').exec; 7 | var escape = require('shell-escape'); 8 | var os = require('os'); 9 | 10 | // platforms 11 | 12 | switch (os.platform()) { 13 | case 'freebsd': return module.exports = freebsd; 14 | case 'win32': return module.exports = windows; 15 | case 'linux': return module.exports = linux; 16 | case 'darwin': return module.exports = mac; 17 | default: return module.exports = unsupported; 18 | } 19 | 20 | // unsupported 21 | 22 | function unsupported(str, fn) { 23 | fn(new Error('unsupported platform')); 24 | } 25 | 26 | // freebsd 27 | 28 | function freebsd(str, fn) { 29 | execute('xsel -i -b', str, fn); 30 | } 31 | 32 | // windows 33 | 34 | function windows(str, fn) { 35 | execute('clip', str, fn); 36 | } 37 | 38 | // linux 39 | 40 | function linux(str, fn) { 41 | execute('xclip -selection clipboard', str, fn); 42 | } 43 | 44 | // mac 45 | 46 | function mac(str, fn) { 47 | execute('pbcopy', str, fn); 48 | } 49 | 50 | // exec 51 | 52 | function execute(program, str, fn) { 53 | var cmd = escape(['printf', str]) + ' | ' + program; 54 | exec(cmd, fn || function(){}); 55 | } 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cliparoo", 3 | "version": "1.1.1", 4 | "repo": "visionmedia/node-cliparoo", 5 | "description": "Hacky clipboard support", 6 | "keywords": ["clipboard", "copy"], 7 | "dependencies": { 8 | "shell-escape": "0.0.0" 9 | }, 10 | "devDependencies": { 11 | "mocha": "*", 12 | "should": "*" 13 | }, 14 | "license": "MIT" 15 | } 16 | --------------------------------------------------------------------------------