├── .babelrc ├── .eslintignore ├── .gitignore ├── .istanbul.yml ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── bin ├── alias.js ├── cash.js ├── cat.js ├── cd.js ├── clear.js ├── cp.js ├── echo.js ├── export.js ├── false.js ├── grep.js ├── head.js ├── kill.js ├── less.js ├── ls.js ├── mkdir.js ├── mv.js ├── parser.js ├── pwd.js ├── rm.js ├── sort.js ├── source.js ├── tail.js ├── touch.js ├── true.js ├── unalias.js └── which.js ├── commands.json ├── dist ├── commands │ ├── alias.js │ ├── boilerplate.js │ ├── cat.js │ ├── cd.js │ ├── clear.js │ ├── cp.js │ ├── echo.js │ ├── export.js │ ├── false.js │ ├── grep.js │ ├── head.js │ ├── kill.js │ ├── less.js │ ├── ls.js │ ├── mkdir.js │ ├── mv.js │ ├── pwd.js │ ├── rm.js │ ├── sort.js │ ├── source.js │ ├── tail.js │ ├── touch.js │ ├── true.js │ ├── unalias.js │ └── which.js ├── delimiter.js ├── help.js ├── help │ ├── alias.js │ ├── cat.js │ ├── cd.js │ ├── clear.js │ ├── cp.js │ ├── echo.js │ ├── export.js │ ├── false.js │ ├── grep.js │ ├── head.js │ ├── kill.js │ ├── ls.js │ ├── mkdir.js │ ├── mv.js │ ├── pwd.js │ ├── rm.js │ ├── sort.js │ ├── source.js │ ├── tail.js │ ├── touch.js │ ├── true.js │ ├── unalias.js │ └── which.js ├── index.js ├── lib │ └── sugar.js ├── preparser.js ├── util │ ├── colorFile.js │ ├── columnify.js │ ├── converter.date.js │ ├── converter.path.js │ ├── converter.permissions.js │ ├── expand.js │ ├── fetch.js │ ├── fileFromPath.js │ ├── intercept.js │ ├── interfacer.js │ ├── lpad.js │ ├── pad.js │ ├── stripAnsi.js │ ├── unlinkSync.js │ ├── walkDir.js │ └── walkDirRecursive.js └── windows.js ├── gulpfile.js ├── package.json ├── packages ├── cat │ ├── README.md │ ├── bin │ │ ├── cat.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── cat.js │ │ ├── help │ │ │ └── cat.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ ├── fetch.js │ │ │ ├── interfacer.js │ │ │ ├── lpad.js │ │ │ └── stripAnsi.js │ └── package.json ├── cp │ ├── README.md │ ├── bin │ │ ├── cp.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── cp.js │ │ ├── help │ │ │ └── cp.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ └── interfacer.js │ └── package.json ├── false │ ├── README.md │ ├── bin │ │ ├── false.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── false.js │ │ ├── help │ │ │ └── false.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json ├── head │ ├── README.md │ ├── bin │ │ ├── head.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── head.js │ │ ├── help │ │ │ └── head.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ └── interfacer.js │ └── package.json ├── kill │ ├── README.md │ ├── bin │ │ ├── kill.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── kill.js │ │ ├── help │ │ │ └── kill.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json ├── ls │ ├── README.md │ ├── bin │ │ ├── ls.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── ls.js │ │ ├── help │ │ │ └── ls.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── colorFile.js │ │ │ ├── columnify.js │ │ │ ├── converter.date.js │ │ │ ├── converter.permissions.js │ │ │ ├── expand.js │ │ │ ├── fileFromPath.js │ │ │ ├── interfacer.js │ │ │ ├── lpad.js │ │ │ ├── pad.js │ │ │ ├── stripAnsi.js │ │ │ ├── walkDir.js │ │ │ └── walkDirRecursive.js │ └── package.json ├── mkdir │ ├── README.md │ ├── bin │ │ ├── mkdir.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── mkdir.js │ │ ├── help │ │ │ └── mkdir.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json ├── mv │ ├── README.md │ ├── bin │ │ ├── mv.js │ │ └── parser.js │ ├── dist │ │ ├── commands │ │ │ └── mv.js │ │ ├── help │ │ │ └── mv.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ └── interfacer.js │ └── package.json ├── pwd │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── pwd.js │ ├── dist │ │ ├── commands │ │ │ └── pwd.js │ │ ├── help │ │ │ └── pwd.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json ├── rm │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── rm.js │ ├── dist │ │ ├── commands │ │ │ └── rm.js │ │ ├── help │ │ │ └── rm.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ ├── interfacer.js │ │ │ └── unlinkSync.js │ └── package.json ├── sort │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── sort.js │ ├── dist │ │ ├── commands │ │ │ └── sort.js │ │ ├── help │ │ │ └── sort.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── expand.js │ │ │ ├── fetch.js │ │ │ ├── interfacer.js │ │ │ └── stripAnsi.js │ └── package.json ├── tail │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── tail.js │ ├── dist │ │ ├── commands │ │ │ └── tail.js │ │ ├── help │ │ │ └── tail.js │ │ ├── preparser.js │ │ └── util │ │ │ ├── converter.path.js │ │ │ ├── expand.js │ │ │ └── interfacer.js │ └── package.json ├── template.README.md ├── template.package.json ├── touch │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── touch.js │ ├── dist │ │ ├── commands │ │ │ └── touch.js │ │ ├── help │ │ │ └── touch.js │ │ ├── lib │ │ │ └── sugar.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json ├── true │ ├── README.md │ ├── bin │ │ ├── parser.js │ │ └── true.js │ ├── dist │ │ ├── commands │ │ │ └── true.js │ │ ├── help │ │ │ └── true.js │ │ ├── preparser.js │ │ └── util │ │ │ └── interfacer.js │ └── package.json └── which │ ├── README.md │ ├── bin │ ├── parser.js │ └── which.js │ ├── dist │ ├── commands │ │ └── which.js │ ├── help │ │ └── which.js │ ├── preparser.js │ └── util │ │ └── interfacer.js │ └── package.json ├── src ├── commands │ ├── alias.js │ ├── boilerplate.js │ ├── cat.js │ ├── cd.js │ ├── clear.js │ ├── cp.js │ ├── echo.js │ ├── export.js │ ├── false.js │ ├── grep.js │ ├── head.js │ ├── kill.js │ ├── less.js │ ├── ls.js │ ├── mkdir.js │ ├── mv.js │ ├── pwd.js │ ├── rm.js │ ├── sort.js │ ├── source.js │ ├── tail.js │ ├── touch.js │ ├── true.js │ ├── unalias.js │ └── which.js ├── delimiter.js ├── help.js ├── help │ ├── alias.js │ ├── cat.js │ ├── cd.js │ ├── clear.js │ ├── cp.js │ ├── echo.js │ ├── export.js │ ├── false.js │ ├── grep.js │ ├── head.js │ ├── kill.js │ ├── ls.js │ ├── mkdir.js │ ├── mv.js │ ├── pwd.js │ ├── rm.js │ ├── sort.js │ ├── source.js │ ├── tail.js │ ├── touch.js │ ├── true.js │ ├── unalias.js │ └── which.js ├── index.js ├── lib │ └── sugar.js ├── preparser.js ├── util │ ├── colorFile.js │ ├── columnify.js │ ├── converter.date.js │ ├── converter.path.js │ ├── converter.permissions.js │ ├── expand.js │ ├── fetch.js │ ├── fileFromPath.js │ ├── intercept.js │ ├── interfacer.js │ ├── lpad.js │ ├── pad.js │ ├── stripAnsi.js │ ├── unlinkSync.js │ ├── walkDir.js │ └── walkDirRecursive.js └── windows.js └── test ├── alias.js ├── cat.js ├── cd.js ├── clear.js ├── cp.js ├── echo.js ├── export.js ├── head.js ├── help.js ├── index.js ├── kill.js ├── ls.js ├── mkdir.js ├── mv.js ├── preparser.js ├── pwd.js ├── rm.js ├── sort.js ├── source.js ├── tail.js ├── touch.js ├── true.js ├── unalias.js ├── util ├── playground.js └── util.js ├── vorpal.js ├── which.js └── windows.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | src/lib/sugar.js -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | 3 | # Runtime data 4 | pids 5 | *.pid 6 | *.seed 7 | 8 | *sublime* 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | .cmd_history 30 | .cmd_history/* 31 | .cmd_history/cmd_historycash 32 | -------------------------------------------------------------------------------- /.istanbul.yml: -------------------------------------------------------------------------------- 1 | verbose: false 2 | instrumentation: 3 | root: . 4 | extensions: 5 | - .js 6 | default-excludes: true 7 | excludes: ['./dist/lib/sugar.js'] 8 | embed-source: false 9 | variable: __coverage__ 10 | compact: true 11 | preserve-comments: false 12 | complete-copy: false 13 | save-baseline: false 14 | baseline-file: ./coverage/coverage-baseline.json 15 | include-all-sources: false 16 | include-pid: false 17 | es-modules: false 18 | reporting: 19 | print: summary 20 | reports: 21 | - lcov 22 | dir: ./coverage 23 | watermarks: 24 | statements: [50, 80] 25 | lines: [50, 80] 26 | functions: [50, 80] 27 | branches: [50, 80] 28 | report-config: 29 | clover: {file: clover.xml} 30 | cobertura: {file: cobertura-coverage.xml} 31 | json: {file: coverage-final.json} 32 | json-summary: {file: coverage-summary.json} 33 | lcovonly: {file: lcov.info} 34 | teamcity: {file: null, blockName: Code Coverage Summary} 35 | text: {file: null, maxCols: 0} 36 | text-lcov: {file: lcov.info} 37 | text-summary: {file: null} 38 | hooks: 39 | hook-run-in-context: false 40 | post-require-hook: null 41 | handle-sigint: false 42 | check: 43 | global: 44 | statements: 0 45 | lines: 0 46 | branches: 0 47 | functions: 0 48 | excludes: [] 49 | each: 50 | statements: 0 51 | lines: 0 52 | branches: 0 53 | functions: 0 54 | excludes: [] 55 | 56 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "7" 5 | - "6" 6 | - "5" 7 | - "4" 8 | - "8" 9 | after_success: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" 10 | branches: 11 | only: 12 | - master 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2015 DC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '7' 4 | - nodejs_version: '6' 5 | - nodejs_version: '5' 6 | - nodejs_version: '4' 7 | - nodejs_version: '8' 8 | install: 9 | - ps: Install-Product node $env:nodejs_version 10 | - set CI=true 11 | - set CASH_APPVEYOR=true 12 | - npm install -g npm@latest || (timeout 30 && npm install -g npm@latest) 13 | - set PATH=%APPDATA%\npm;%PATH% 14 | - npm install || (timeout 30 && npm install) 15 | matrix: 16 | fast_finish: true 17 | build: off 18 | version: '{build}' 19 | shallow_clone: true 20 | clone_depth: 1 21 | test_script: 22 | - node --version 23 | - npm --version 24 | - npm run test-win || (timeout 30 && npm run test-win) 25 | -------------------------------------------------------------------------------- /bin/alias.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'alias'); 3 | -------------------------------------------------------------------------------- /bin/cash.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var cash = require('../dist/index'); 4 | var delimiter = require('./../dist/delimiter') 5 | delimiter.refresh(cash.vorpal, function () { 6 | cash.show(); 7 | }); 8 | -------------------------------------------------------------------------------- /bin/cat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'cat'); 3 | -------------------------------------------------------------------------------- /bin/cd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'cd'); 3 | -------------------------------------------------------------------------------- /bin/clear.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'clear'); 3 | -------------------------------------------------------------------------------- /bin/cp.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'cp'); 3 | -------------------------------------------------------------------------------- /bin/echo.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'echo'); 3 | -------------------------------------------------------------------------------- /bin/export.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'export'); 3 | -------------------------------------------------------------------------------- /bin/false.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'false'); 3 | -------------------------------------------------------------------------------- /bin/grep.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'grep'); 3 | -------------------------------------------------------------------------------- /bin/head.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'head'); 3 | -------------------------------------------------------------------------------- /bin/kill.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'kill'); 3 | -------------------------------------------------------------------------------- /bin/less.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'less'); 3 | -------------------------------------------------------------------------------- /bin/ls.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'ls'); 3 | -------------------------------------------------------------------------------- /bin/mkdir.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'mkdir'); 3 | -------------------------------------------------------------------------------- /bin/mv.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'mv'); 3 | -------------------------------------------------------------------------------- /bin/pwd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'pwd'); 3 | -------------------------------------------------------------------------------- /bin/rm.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'rm'); 3 | -------------------------------------------------------------------------------- /bin/sort.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'sort'); 3 | -------------------------------------------------------------------------------- /bin/source.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'source'); 3 | -------------------------------------------------------------------------------- /bin/tail.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'tail'); 3 | -------------------------------------------------------------------------------- /bin/touch.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'touch'); 3 | -------------------------------------------------------------------------------- /bin/true.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'true'); 3 | -------------------------------------------------------------------------------- /bin/unalias.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'unalias'); 3 | -------------------------------------------------------------------------------- /bin/which.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'which'); 3 | -------------------------------------------------------------------------------- /dist/commands/cd.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fsAutocomplete = require('vorpal-autocomplete-fs'); 4 | var delimiter = require('./../delimiter'); 5 | 6 | var interfacer = require('./../util/interfacer'); 7 | var preparser = require('./../preparser'); 8 | 9 | var cd = { 10 | exec: function exec(dir, options) { 11 | var self = this; 12 | var vpl = options.vorpal; 13 | options = options || {}; 14 | 15 | dir = !dir ? delimiter.getHomeDir() : dir; 16 | 17 | // Allow Windows drive letter changes 18 | dir = dir && dir.length === 2 && dir[1] === '/' ? dir[0] + ':' : dir; 19 | 20 | try { 21 | process.chdir(dir); 22 | if (vpl) { 23 | delimiter.refresh(vpl); 24 | } 25 | return 0; 26 | } catch (e) { 27 | return cd.error.call(self, e, dir); 28 | } 29 | }, 30 | error: function error(e, dir) { 31 | var status = void 0; 32 | var stdout = void 0; 33 | if (e.code === 'ENOENT' && e.syscall === 'uv_chdir') { 34 | status = 1; 35 | stdout = '-bash: cd: ' + dir + ': No such file or directory'; 36 | } else { 37 | status = 2; 38 | stdout = e.stack; 39 | } 40 | this.log(stdout); 41 | return status; 42 | } 43 | }; 44 | 45 | module.exports = function (vorpal) { 46 | if (vorpal === undefined) { 47 | return cd; 48 | } 49 | vorpal.api.cd = cd; 50 | vorpal.command('cd [dir]').parse(preparser).autocomplete(fsAutocomplete({ directory: true })).action(function (args, callback) { 51 | args.options = args.options || {}; 52 | args.options.vorpal = vorpal; 53 | return interfacer.call(this, { 54 | command: cd, 55 | args: args.dir, 56 | options: args.options, 57 | callback: callback 58 | }); 59 | }); 60 | }; -------------------------------------------------------------------------------- /dist/commands/clear.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | 5 | var clear = { 6 | exec: function exec() { 7 | this.log('\u001b[2J\u001b[0;0H'); 8 | return 0; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return clear; 15 | } 16 | vorpal.api.clear = clear; 17 | vorpal.command('clear').action(function (args, callback) { 18 | args.options = args.options || {}; 19 | return interfacer.call(this, { 20 | command: clear, 21 | args: args, 22 | options: args.options, 23 | callback: callback 24 | }); 25 | }); 26 | }; -------------------------------------------------------------------------------- /dist/commands/false.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | 5 | var _false = { 6 | exec: function exec() { 7 | // Always return 1 8 | return 1; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _false; 15 | } 16 | vorpal.api.false = _false; 17 | vorpal.command('false').action(function (args, callback) { 18 | return interfacer.call(this, { 19 | command: _false, 20 | callback: callback 21 | }); 22 | }); 23 | }; -------------------------------------------------------------------------------- /dist/commands/grep.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('vorpal-grep'); -------------------------------------------------------------------------------- /dist/commands/less.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('vorpal-less'); -------------------------------------------------------------------------------- /dist/commands/pwd.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | 5 | var interfacer = require('./../util/interfacer'); 6 | 7 | var pwd = { 8 | exec: function exec() { 9 | this.log(path.resolve(process.cwd()).replace(/\\/g, '/')); 10 | return 0; 11 | } 12 | }; 13 | 14 | module.exports = function (vorpal) { 15 | if (vorpal === undefined) { 16 | return pwd; 17 | } 18 | vorpal.api.pwd = pwd; 19 | vorpal.command('pwd [files...]').action(function (args, callback) { 20 | args.options = args.options || {}; 21 | return interfacer.call(this, { 22 | command: pwd, 23 | args: args.files, 24 | options: args.options, 25 | callback: callback 26 | }); 27 | }); 28 | }; -------------------------------------------------------------------------------- /dist/commands/true.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | 5 | var _true = { 6 | exec: function exec() { 7 | // Always return 0 8 | return 0; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _true; 15 | } 16 | vorpal.api.true = _true; 17 | vorpal.command('true').action(function (args, callback) { 18 | return interfacer.call(this, { 19 | command: _true, 20 | callback: callback 21 | }); 22 | }); 23 | }; -------------------------------------------------------------------------------- /dist/commands/which.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | var preparser = require('./../preparser'); 5 | 6 | var which = { 7 | exec: function exec(args, options) { 8 | options = options || {}; 9 | 10 | var command = (args instanceof Array ? args : [args]).join(' '); 11 | if (command.length <= 0) { 12 | return 0; 13 | } 14 | try { 15 | this.log(require('which').sync(command)); 16 | return 0; 17 | } catch (error) { 18 | this.log(error); 19 | return 1; 20 | } 21 | } 22 | }; 23 | 24 | module.exports = function (vorpal) { 25 | if (vorpal === undefined) { 26 | return which; 27 | } 28 | vorpal.api.which = which; 29 | 30 | vorpal.command('which [command]').parse(preparser).action(function (args, callback) { 31 | return interfacer.call(this, { 32 | command: which, 33 | args: args.command, 34 | options: {}, 35 | callback: callback 36 | }); 37 | }); 38 | }; -------------------------------------------------------------------------------- /dist/delimiter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var os = require('os'); 4 | var username = require('username'); 5 | var userHome = require('user-home'); 6 | 7 | var isWindows = process.platform === 'win32'; 8 | var pathConverter = require('./util/converter.path'); 9 | 10 | module.exports = { 11 | refresh: function refresh(vorpal, cb) { 12 | cb = cb || function () {}; 13 | username().then(function (username) { 14 | var user = username; 15 | var host = String(os.hostname()).split('.')[0]; 16 | var home = pathConverter.unix(userHome); 17 | var cwd = pathConverter.unix(process.cwd()); 18 | cwd = cwd.replace(home, '~'); 19 | var delimiter = user + '@' + host + ':' + cwd + '$'; 20 | // If we're on linux-based systems, color 21 | // the prompt so we don't get confused. 22 | if (!isWindows) { 23 | delimiter = '\u001b[32m' + delimiter + '\u001b[39m'; 24 | } 25 | vorpal.delimiter(delimiter); 26 | cb(null); 27 | }).catch(function (err) { 28 | return cb(err); 29 | }); 30 | }, 31 | getHomeDir: function getHomeDir() { 32 | return userHome; 33 | } 34 | }; -------------------------------------------------------------------------------- /dist/help/alias.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: alias [OPTION] [name[=value] ...]\nDefine or display aliases.\n\nWithout arguments, `alias' prints the list of aliases in the reusable\nform `alias NAME=VALUE' on standard output.\n\nOtherwise, an alias is defined for each NAME whose VALUE is given.\nA trailing space in VALUE causes the next word to be checked for\nalias substitution when the alias is expanded.\n\n -p print all defined aliases in a reusable format\n --help display this help and exit\n\nReport alias bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/cat.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: cat [OPTION]... [FILE]...\nConcatenate FILE(s), or standard input, to standard output.\n\n -A, --show-all equivalent to -vET\n -b, --number-nonblank number nonempty output lines, overrides -n\n -e equivalent to -vE\n -E, --show-ends display $ at end of each line\n -n, --number number all output lines\n -s, --squeeze-blank suppress repeated empty output lines\n -t equivalent to -vT\n -T, --show-tabs display TAB characters as ^I\n -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB\n --help display this help and exit\n\nWith no FILE, or when FILE is -, read standard input.\n\nExamples:\n cat f - g Output f's contents, then standard input, then g's contents.\n cat Copy standard input to standard output.\n\nReport cat bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/cd.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: cd [DIR]...\nChange the cash working directory.\n\nChange the current directory to DIR. The default DIR is the value of the\nHOME shell variable.\n\nReport cd bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/clear.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: clear\nClear the terminal screen\n\n --help display this help and exit\n\nClear ignores any command-line parameters that may be present.\n\nReport clear bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/cp.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: cp [OPTION]... [-T] SOURCE DEST\n or: cp [OPTION]... SOURCE... DIRECTORY\nCopy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\n -f, --force if an existing destination file cannot be\n opened, remove it and try again (this option\n is ignored when the -n option is also used)\n -n, --no-clobber do not overwrite an existing file (overrides\n a previous -i option)\n -R, -r, --recursive copy directories recursively\n --help display this help and exit\n\nReport cp bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/echo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: echo [OPTION]... [ARG ...]\nWrite arguments to the standard output.\n\nDisplay the ARGs, separated by a single space character and followed by a\nnewline, on the standard output.\n\n -e enable interpretation of the following backslash escapes\n -e explicitly suppress interpretation of backslash escapes\n --help display this help and exit\n\n `echo' interprets the following backslash-escaped characters:\n \b backspace\n c suppress further output\n \n new line\n \r carriage return\n \t horizontal tab\n \\ backslash\n\nReport echo bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/export.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: export [OPTION] [name[=value]]\nExport variables into the environment\n\nWithout arguments, `export' prints the list of environnmental variables in the\nform `declare -x NAME=\"VALUE\"' on standard output. This is the same as the\nbehavior if `-p' is given.\n\nOtherwise, the variable is exported to the environment. If the variable has\nalready been defined in the environment (ex. `PATH'), then this will either\nredefine its value or do nothing (if no value is passed in). If the variable is\nnot already in the environment, it will be added with the `VALUE' given\n(defaults to the empty string).\n\n -p print all exported variables in a reusable format\n --help display this help and exit\n\nReport export bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/false.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: false [OPTION]\nDo nothing, unsuccessfully\n\nThis command simply exits with status 1 (failure).\n\n --help display this help and exit\n\nReport false bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/grep.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: grep [OPTION]... PATTERN [FILE]...\nSearch for PATTERN in each FILE or standard input.\nPATTERN is, by default, a basic regular expression (BRE).\nExample: grep -i 'hello world' menu.h main.c\n\niwsvmbnHhqr\n\nRegexp selection and interpretation:\n -i, --ignore-case ignore case distinctions\n -w, --word-regexp force PATTERN to match only whole words\n\nMiscellaneous:\n -s, --no-messages suppress error messages\n -v, --invert-match select non-matching lines\n --help display this help and exit\n\nOutput control:\n -n, --line-number print line number with output lines\n -H, --with-filename print the file name for each match\n -h, --no-filename suppress the file name prefix on output\n -q, --quiet, --silent suppress all normal output\n -r, --recursive like --directories=recurse\n --include search only files that match FILE_PATTERN\n\nWhen FILE is -, read standard input. With no FILE, read . if a command-line\n-r is given, - otherwise. If fewer than two FILEs are given, assume -h.\nExit status is 0 if any line is selected, 1 otherwise;\nif any error occurs and -q is not given, the exit status is 2.\n\nReport grep bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/head.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: head [OPTION]... [FILE]...\nPrint the first 10 lines of each FILE to standard output.\nWith more than one FILE, precede each with a header giving the file name.\nWith no FILE, or when FILE is -, read standard input.\n\n -n, --lines output the last N lines, instead of the last 10\n -q, --silent suppresses printing of headers when multiple files\n are being examined\n -v, --verbose always output headers giving file names\n --help display this help and exit\n\nReport head bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/kill.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: kill [OPTION] pid | jobspec ... or kill -l [sigspec]\nSend a signal to a job.\n\nSend the processes identified by PID or JOBSPEC the signal named by\nSIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then\nSIGTERM is assumed.\n\n -s sig SIG is a signal name\n -n sig SIG is a signal number\n -l [sigspec] list the signal names; if arguments follow `-l' they\n are assumed to be signal numbers for which names\n should be listed\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if an invalid option is given or an error occurs.\n\nReport kill bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/ls.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: ls [OPTION]... [FILE]...\nList information about the FILEs (the current directory by default).\nSort entries alphabetically if none of -tSU nor --sort is specified.\n\n -a, --all do not ignore entries starting with .\n -A, --almost-all do not list implied . and ..\n -d, --directory list directory entries instead of contents,\n and do not dereference symbolic links\n -f do not sort, enable -aU, disable -ls --color\n -F, --classify append indicator (one of */=>@|) to entries\n -h, --human-readable with -l, print sizes in human readable format\n -i, --inode print the index number of each file\n -l use a long listing format\n -q, --hide-control-chars print ? instead of non graphic characters\n -r, --reverse reverse order while sorting\n -R, --recursive list subdirectories recursively\n -S sort by file size\n -t sort by modification time, newest first\n -U do not sort; list entries in directory order\n -w, --width=COLS assume screen width instead of current value\n -x list entries by lines instead of by columns\n -1 list one file per line\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if minor problems (e.g., cannot access subdirectory),\n 2 if serious trouble (e.g., cannot access command-line argument).\n\nReport ls bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/mkdir.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: mkdir [OPTION]... DIRECTORY...\nCreate the DIRECTORY(ies), if they do not already exist.\n\n -p, --parents no error if existing, make parent directories as needed\n -v, --verbose print a message for each created directory\n --help display this help and exit\n\nReport mkdir bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/mv.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: mv [OPTION]... [-T] SOURCE DEST\n or: mv [OPTION]... SOURCE... DIRECTORY\n or: mv [OPTION]... -t DIRECTORY SOURCE...\nRename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\n -f, --force do not prompt before overwriting\n -n, --no-clobber do not overwrite an existing file\n --striptrailingslashes remove any trailing slashes from each SOURCE\n argument\n -v, --verbose explain what is being done\n --help display this help and exit\n\nIf you specify -f and -n, only -f takes effect.\n\nReport mv bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/pwd.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: pwd [-LP]\nPrint the name of the current working directory.\n\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if an invalid option is given or the current directory\n cannot be read.\n\nReport pwd bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/rm.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: rm [OPTION]... FILE...\nRemove (unlink) the FILE(s).\n\n -f, --force ignore nonexistent files and arguments, never prompt\n -r, -R, --recursive remove directories and their contents recursively\n --help display this help and exit\n\nBy default, rm does not remove directories. Use the --recursive (-r or -R)\noption to remove each listed directory, too, along with all of its contents.\n\nTo remove a file whose name starts with a '-', for example '-foo',\nuse one of these commands:\n rm -- -foo\n rm ./-foo\n\nNote that if you use rm to remove a file, it might be possible to recover\nsome of its contents, given sufficient expertise and/or time.\n\nReport rm bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/sort.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: sort [OPTION]... [FILE]...\nWrite sorted concatenation of all FILE(s) to standard output.\n\nOrdering options:\n -M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'\n -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)\n -n, --numeric-sort compare according to string numerical value\n -R, --random-sort sort by random hash of keys\n -r, --reverse reverse the result of comparisons\n\nOther options:\n -c, --check,\n --check=diagnose-first check for sorted input; do not sort\n -o, --output=FILE write result to FILE instead of standard output\n --help display this help and exit\n\nWith no FILE, or when FILE is -, read standard input.\n\nReport sort bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/source.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: source FILENAME [ARGUMENTS...]\n or: . FILENAME [ARGUMENTS...]\nRead and execute commands from the filename argument in the current shell.\n\nWhen a script is run using source, it runs within the existing shell and any\nchange of directory or modified variables or aliases will persist after the\nscript completes. Scripts may contain any commands that cash supports.\n\n --help display this help and exit\n\nReport source bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/tail.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: tail [OPTION]... [FILE]...\nDisplay the last part of a file.\n\nPrint the last 10 lines of each FILE to standard output. With more\nthan one FILE, precede each with a header giving the file name.\n\n -n, --lines output the last N lines, instead of the last 10\n -q, --silent suppresses printing of headers when multiple files\n are being examined\n -v, --verbose always output headers giving file names\n --help display this help and exit\n\nReport tail bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/touch.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: touch [OPTION]... FILE...\nUpdate the access and modification times of each FILE to the current time.\n\nA FILE argument that does not exist is created empty, unless -c is\nsupplied.\n\n -a change only the access time\n -c, --no-create do not create any files\n -d, --date parse STRING and use it instead of current time\n -m change only the modification time\n -r, --reference use this file's times instead of current time\n --time change the specified time:\n WORD is access, atime, or use: equivalent to -a\n WORD is modify or mtime: equivalent to -m\n --help display this help and exit\n\nReport touch bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/true.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: true [OPTION]\nDo nothing, successfully\n\nThis command simply exits with status 0 (success).\n\n --help display this help and exit\n\nReport true bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/unalias.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: unalias [OPTION] name ...\nRemove each name from the list of defined aliases.\n\n -a remove all alias definitions\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if a name is not an existing alias.\n\nReport unalias bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/help/which.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: which COMMAND\nLook for COMMAND in $PATH.\n\n --help display this help and exit\n\nReport which bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /dist/util/colorFile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | var chalk = {}; 6 | var map = { cyan: 36, red: 31, magenta: 35 }; 7 | Object.keys(map).forEach(function (key, value) { 8 | chalk[key] = function (str) { 9 | return '\u001b[' + value + 'm' + str + '\u001b[39m'; 10 | }; 11 | }); 12 | 13 | /** 14 | * Wraps file strings in ANSI colors 15 | * based on their extension. 16 | * 17 | * @param {file} str 18 | * @return {String} 19 | * @api public 20 | */ 21 | 22 | module.exports = function (file) { 23 | var audio = ['aac', 'au', 'flac', 'mid', 'midi', 'mka', 'mp3', 'mpc', 'ogg', 'ra', 'wav', 'axa', 'oga', 'spx', 'xspf']; 24 | var archive = ['tar', 'tgz', 'arj', 'taz', 'lzh', 'lzma', 'tlz', 'txz', 'zip', 'z', 'Z', 'dz', 'gz', 'lz', 'xz', 'bz2', 'bz', 'tbz', 'tbz2', 'tz', 'deb', 'rpm', 'jar', 'rar', 'ace', 'zoo', 'cpio', '7z', 'rz']; 25 | var images = ['jpg', 'jpeg', 'gif', 'bmp', 'pbm', 'pgm', 'ppm', 'tga', 'xbm', 'xpm', 'tif', 'tiff', 'png', 'svg', 'svgz', 'mng', 'pcx', 'mov', 'mpg', 'mpeg', 'm2v', 'mkv', 'ogm', 'mp4', 'm4v', 'mp4v', 'vob', 'qt', 'nuv', 'wmv', 'asf', 'rm', 'rmvb', 'flc', 'avi', 'fli', 'flv', 'gl', 'dl', 'xcf', 'xwd', 'yuv', 'cgm', 'emf', 'axv', 'anx', 'ogv', 'ogx']; 26 | 27 | var extension = String(file).toLowerCase().trim().split('.'); 28 | extension = extension[extension.length - 1]; 29 | 30 | var colored = strip(file); 31 | colored = audio.indexOf(extension) > -1 ? chalk.cyan(file) : archive.indexOf(extension) > -1 ? chalk.red(file) : images.indexOf(extension) > -1 ? chalk.magenta(file) : colored; 32 | 33 | return colored; 34 | }; -------------------------------------------------------------------------------- /dist/util/columnify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | var pad = require('./pad'); 5 | 6 | /** 7 | * Formats an array to display in a TTY 8 | * in a pretty fashion. 9 | * 10 | * @param {Array} arr 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (arr, options) { 16 | arr = arr || []; 17 | options = options || {}; 18 | var bk = JSON.parse(JSON.stringify(arr)); 19 | var width = options.width && !isNaN(options.width) ? options.width : process.stdout.columns; 20 | var longest = strip(bk.sort(function (a, b) { 21 | return strip(b).length - strip(a).length; 22 | })[0] || '').length + 2; 23 | var fullWidth = strip(arr.join('')).length; 24 | var fitsOneLine = fullWidth + arr.length * 2 <= width; 25 | var cols = Math.floor(width / longest); 26 | cols = cols < 1 ? 1 : cols; 27 | if (fitsOneLine) { 28 | return arr.join(' '); 29 | } 30 | var col = 0; 31 | var lines = []; 32 | var line = ''; 33 | for (var i = 0; i < arr.length; ++i) { 34 | if (col < cols) { 35 | col++; 36 | } else { 37 | if (String(strip(line)).trim() !== '') { 38 | lines.push(line); 39 | } 40 | line = ''; 41 | col = 1; 42 | } 43 | if (cols === 1) { 44 | // If we have files so damn 45 | // long that we wrap, don't pad 46 | // the lines. 47 | line += arr[i]; 48 | } else { 49 | // Pad the lines based on the 50 | // longest word. 51 | /* istanbul ignore next */ 52 | line += pad(arr[i], longest, ' '); 53 | } 54 | } 55 | if (line !== '') { 56 | lines.push(line); 57 | } 58 | return lines.join('\n'); 59 | }; -------------------------------------------------------------------------------- /dist/util/converter.date.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Date conversion utilities 5 | */ 6 | 7 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 8 | 9 | function pad(num, padding) { 10 | padding = padding || '0'; 11 | num = parseFloat(num); 12 | if (num < 10) { 13 | return '' + padding + num; 14 | } 15 | return num; 16 | } 17 | 18 | module.exports = { 19 | unix: function unix(dt) { 20 | var date = dt; 21 | var day = pad(date.getDate(), ' '); 22 | var month = months[date.getMonth()]; 23 | var hour = pad(date.getHours()); 24 | var min = pad(date.getMinutes()); 25 | var hourMin = hour + ':' + min; 26 | day = day.length === 1 ? ' ' + day : day; 27 | date = month + ' ' + day + ' ' + hourMin; 28 | return date; 29 | } 30 | }; -------------------------------------------------------------------------------- /dist/util/converter.path.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | 5 | /** 6 | * Path conversion utilities 7 | */ 8 | 9 | module.exports = { 10 | unix: function unix(str) { 11 | var input = path.normalize(str); 12 | input = input.replace(/\\/g, '\/'); 13 | var parts = input.split(':'); 14 | var drive = parts.shift(); 15 | var isLetter = drive.length === 1 && drive.match(/[a-z]/i); 16 | var result = isLetter ? drive + parts.join(':') : input; 17 | return result; 18 | } 19 | }; -------------------------------------------------------------------------------- /dist/util/converter.permissions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Permission conversion utilities 5 | */ 6 | 7 | module.exports = { 8 | 9 | listing: { 10 | 0: '---', 11 | 1: '--x', 12 | 2: '-w-', 13 | 3: '-wx', 14 | 4: 'r--', 15 | 5: 'r-x', 16 | 6: 'rw-', 17 | 7: 'rwx' 18 | }, 19 | 20 | modeToRWX: function modeToRWX(mode) { 21 | var octal = this.modeToOctal(mode); 22 | var rwx = this.octalToRWX(octal); 23 | return rwx; 24 | }, 25 | modeToOctal: function modeToOctal(mode) { 26 | var octal = '0' + (mode & 511).toString(8); 27 | return octal; 28 | }, 29 | octalToRWX: function octalToRWX(octal) { 30 | if (!octal) { 31 | return undefined; 32 | } 33 | var list = this.listing; 34 | var a = list[String(octal).charAt(1)]; 35 | var b = list[String(octal).charAt(2)]; 36 | var c = list[String(octal).charAt(3)]; 37 | return a + b + c; 38 | } 39 | }; -------------------------------------------------------------------------------- /dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /dist/util/fetch.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | var expand = require('./expand'); 7 | 8 | /** 9 | * Reads the contents of an array of 10 | * files and returns the array. 11 | * 12 | * @param {Array} files 13 | * @param {String} stdin 14 | * @param {Object} options 15 | * @return {Array} 16 | * @api public 17 | */ 18 | 19 | module.exports = function (files, stdin, options) { 20 | files = files || []; 21 | stdin = stdin !== undefined ? stdin : []; 22 | var f = expand(files); 23 | 24 | if (!(f.length === 0 && files.length > 0)) { 25 | files = f; 26 | } 27 | 28 | for (var i = 0; i < files.length; ++i) { 29 | try { 30 | var stat = fs.statSync(files[i]); 31 | if (stat.isDirectory()) { 32 | files[i] = options.onDirectory(files[i]); 33 | } else { 34 | files[i] = String(fs.readFileSync(path.normalize(files[i]), 'utf8')); 35 | } 36 | } catch (e) { 37 | files[i] = options.onInvalidFile(files[i]); 38 | } 39 | } 40 | 41 | var agg = files.length < 1 ? stdin : files; 42 | var final = []; 43 | 44 | for (var _i = 0; _i < agg.length; ++_i) { 45 | if (agg[_i] !== undefined) { 46 | final.push(agg[_i]); 47 | } 48 | } 49 | return final; 50 | }; -------------------------------------------------------------------------------- /dist/util/fileFromPath.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Parses a path and returns just the file 5 | * 6 | * @param {path} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (path) { 12 | var fileShort = String(path).split('/'); 13 | fileShort = fileShort[fileShort.length - 1]; 14 | fileShort = fileShort.split('\\'); 15 | fileShort = fileShort[fileShort.length - 1]; 16 | return fileShort; 17 | }; -------------------------------------------------------------------------------- /dist/util/intercept.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Intercepts stdout, passes thru callback 5 | * also pass console.error thru stdout so it goes to callback too 6 | * (stdout.write and stderr.write are both refs to the same stream.write function) 7 | * returns an unhook() function, call when done intercepting 8 | * 9 | * @param {Function} callback 10 | * @return {Function} 11 | */ 12 | 13 | module.exports = function (callback) { 14 | var oldStdoutWrite = process.stdout.write; 15 | var oldConsoleError = console.error; 16 | process.stdout.write = function (write) { 17 | return function (string) { 18 | var args = Array.from(arguments); 19 | args[0] = interceptor(string); 20 | write.apply(process.stdout, args); 21 | }; 22 | }(process.stdout.write); 23 | 24 | console.error = function () { 25 | return function () { 26 | var args = Array.from(arguments); 27 | args.unshift('\x1b[31m[ERROR]\x1b[0m'); 28 | console.log.apply(console.log, args); 29 | }; 30 | }(console.error); 31 | 32 | function interceptor(string) { 33 | // only intercept the string 34 | var result = callback(string); 35 | if (typeof result === 'string') { 36 | string = result.replace(/\n$/, '') + (result && /\n$/.test(string) ? '\n' : ''); 37 | } 38 | return string; 39 | } 40 | // puts back to original 41 | return function unhook() { 42 | process.stdout.write = oldStdoutWrite; 43 | console.error = oldConsoleError; 44 | }; 45 | }; -------------------------------------------------------------------------------- /dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /dist/util/lpad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads to the left hand. 7 | * 8 | * @param {String} str 9 | * @param {Integer} width 10 | * @param {String} delimiter 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (str, width, delimiter) { 16 | width = Math.floor(width); 17 | delimiter = delimiter || ' '; 18 | var len = Math.max(0, width - strip(str).length); 19 | return Array(len + 1).join(delimiter) + str; 20 | }; -------------------------------------------------------------------------------- /dist/util/pad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads a value with with space or 7 | * a specified delimiter to match a 8 | * given width. 9 | * 10 | * @param {String} str 11 | * @param {Integer} width 12 | * @param {String} delimiter 13 | * @return {String} 14 | * @api public 15 | */ 16 | 17 | module.exports = function (str, width, delimiter) { 18 | width = Math.floor(width); 19 | delimiter = delimiter || ' '; 20 | var len = Math.max(0, width - strip(str).length); 21 | return str + Array(len + 1).join(delimiter); 22 | }; -------------------------------------------------------------------------------- /dist/util/stripAnsi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Removes all ansi characters. 5 | * 6 | * @param {String} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (str) { 12 | var ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; 13 | return typeof str === 'string' ? str.replace(ansiRegex, '') : str; 14 | }; -------------------------------------------------------------------------------- /dist/util/unlinkSync.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | 5 | /** 6 | * Normalizes _unlinkSync() across 7 | * platforms to match Unix behavior, i.e. 8 | * file can be unlinked even its it's 9 | * read only. 10 | * See https://github.com/joyent/node/issues/3006 11 | * 12 | * @param {String} file 13 | * @api public 14 | */ 15 | 16 | module.exports = function (file) { 17 | try { 18 | fs.unlinkSync(file); 19 | } catch (e) { 20 | // Try to override file permission 21 | /* istanbul ignore if */ 22 | if (e.code === 'EPERM') { 23 | fs.chmodSync(file, '0666'); 24 | fs.unlinkSync(file); 25 | } else { 26 | /* istanbul ignore next */ 27 | throw e; 28 | } 29 | } 30 | }; -------------------------------------------------------------------------------- /dist/util/walkDir.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | /** 7 | * Walks a single directory calling 8 | * a callback function for each file or 9 | * folder, returning the path and results 10 | * of fs.statSync. 11 | * 12 | * @param {String} currentDirPath 13 | * @param {Function} callback 14 | * @param {Function} errorCallback 15 | * @api public 16 | */ 17 | module.exports = function (currentDirPath, callback, errorCallback) { 18 | /** 19 | * @param {String} path 20 | * @param {Function} cbk 21 | * @param {Function} ecbk 22 | */ 23 | function readFile(path, cbk, ecbk) { 24 | try { 25 | var stat = fs.statSync(path); 26 | if (stat.isFile() || stat.isDirectory()) { 27 | cbk(path, stat); 28 | } 29 | } catch (e) { 30 | ecbk(path, e); 31 | } 32 | } 33 | 34 | try { 35 | var dirs = fs.readdirSync(currentDirPath); 36 | dirs.forEach(function (name) { 37 | var filePath = path.join(currentDirPath, name); 38 | readFile(filePath, callback, errorCallback); 39 | }); 40 | } catch (e) { 41 | if (e.code === 'ENOTDIR') { 42 | readFile(currentDirPath, callback, errorCallback); 43 | } else { 44 | errorCallback(currentDirPath, e); 45 | } 46 | } 47 | }; -------------------------------------------------------------------------------- /dist/util/walkDirRecursive.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | /** 7 | * Recursively walks through and executes 8 | * a callback function for each directory found. 9 | * 10 | * @param {String} currentDirPath 11 | * @param {Function} callback 12 | * @api public 13 | */ 14 | 15 | module.exports = function (currentDirPath, callback) { 16 | fs.readdirSync(currentDirPath).forEach(function (name) { 17 | var filePath = path.join(currentDirPath, name); 18 | var stat = fs.statSync(filePath); 19 | if (stat.isDirectory()) { 20 | callback(filePath, stat); 21 | module.exports(filePath, callback); 22 | } 23 | }); 24 | }; -------------------------------------------------------------------------------- /packages/cat/README.md: -------------------------------------------------------------------------------- 1 | # cash-cat 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `cat` command. 7 | 8 | ```bash 9 | npm install cash-cat -g 10 | ``` 11 | 12 | This will install `cat` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > cat --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/cat/bin/cat.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'cat'); 3 | -------------------------------------------------------------------------------- /packages/cat/dist/help/cat.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: cat [OPTION]... [FILE]...\nConcatenate FILE(s), or standard input, to standard output.\n\n -A, --show-all equivalent to -vET\n -b, --number-nonblank number nonempty output lines, overrides -n\n -e equivalent to -vE\n -E, --show-ends display $ at end of each line\n -n, --number number all output lines\n -s, --squeeze-blank suppress repeated empty output lines\n -t equivalent to -vT\n -T, --show-tabs display TAB characters as ^I\n -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB\n --help display this help and exit\n\nWith no FILE, or when FILE is -, read standard input.\n\nExamples:\n cat f - g Output f's contents, then standard input, then g's contents.\n cat Copy standard input to standard output.\n\nReport cat bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/cat/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/cat/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/cat/dist/util/fetch.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | var expand = require('./expand'); 7 | 8 | /** 9 | * Reads the contents of an array of 10 | * files and returns the array. 11 | * 12 | * @param {Array} files 13 | * @param {String} stdin 14 | * @param {Object} options 15 | * @return {Array} 16 | * @api public 17 | */ 18 | 19 | module.exports = function (files, stdin, options) { 20 | files = files || []; 21 | stdin = stdin !== undefined ? stdin : []; 22 | var f = expand(files); 23 | 24 | if (!(f.length === 0 && files.length > 0)) { 25 | files = f; 26 | } 27 | 28 | for (var i = 0; i < files.length; ++i) { 29 | try { 30 | var stat = fs.statSync(files[i]); 31 | if (stat.isDirectory()) { 32 | files[i] = options.onDirectory(files[i]); 33 | } else { 34 | files[i] = String(fs.readFileSync(path.normalize(files[i]), 'utf8')); 35 | } 36 | } catch (e) { 37 | files[i] = options.onInvalidFile(files[i]); 38 | } 39 | } 40 | 41 | var agg = files.length < 1 ? stdin : files; 42 | var final = []; 43 | 44 | for (var _i = 0; _i < agg.length; ++_i) { 45 | if (agg[_i] !== undefined) { 46 | final.push(agg[_i]); 47 | } 48 | } 49 | return final; 50 | }; -------------------------------------------------------------------------------- /packages/cat/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/cat/dist/util/lpad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads to the left hand. 7 | * 8 | * @param {String} str 9 | * @param {Integer} width 10 | * @param {String} delimiter 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (str, width, delimiter) { 16 | width = Math.floor(width); 17 | delimiter = delimiter || ' '; 18 | var len = Math.max(0, width - strip(str).length); 19 | return Array(len + 1).join(delimiter) + str; 20 | }; -------------------------------------------------------------------------------- /packages/cat/dist/util/stripAnsi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Removes all ansi characters. 5 | * 6 | * @param {String} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (str) { 12 | var ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; 13 | return typeof str === 'string' ? str.replace(ansiRegex, '') : str; 14 | }; -------------------------------------------------------------------------------- /packages/cat/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-cat", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'cat' command.", 5 | "main": "./dist/commands/cat.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "cat": "./bin/cat.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "vorpal-autocomplete-fs": "0.0.3", 40 | "glob": "^7.0.3", 41 | "vorpal": "^1.10.8" 42 | }, 43 | "engines": { 44 | "node": ">= 0.11.16", 45 | "iojs": ">= 1.0.0" 46 | }, 47 | "files": [ 48 | "dist", 49 | "bin" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /packages/cp/README.md: -------------------------------------------------------------------------------- 1 | # cash-cp 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `cp` command. 7 | 8 | ```bash 9 | npm install cash-cp -g 10 | ``` 11 | 12 | This will install `cp` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > cp --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/cp/bin/cp.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'cp'); 3 | -------------------------------------------------------------------------------- /packages/cp/dist/help/cp.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: cp [OPTION]... [-T] SOURCE DEST\n or: cp [OPTION]... SOURCE... DIRECTORY\nCopy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\n -f, --force if an existing destination file cannot be\n opened, remove it and try again (this option\n is ignored when the -n option is also used)\n -n, --no-clobber do not overwrite an existing file (overrides\n a previous -i option)\n -R, -r, --recursive copy directories recursively\n --help display this help and exit\n\nReport cp bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/cp/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/cp/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/cp/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/cp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-cp", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'cp' command.", 5 | "main": "./dist/commands/cp.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "cp": "./bin/cp.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "vorpal-autocomplete-fs": "0.0.3", 40 | "glob": "^7.0.3", 41 | "vorpal": "^1.10.8" 42 | }, 43 | "engines": { 44 | "node": ">= 0.11.16", 45 | "iojs": ">= 1.0.0" 46 | }, 47 | "files": [ 48 | "dist", 49 | "bin" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /packages/false/README.md: -------------------------------------------------------------------------------- 1 | # cash-false 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `false` command. 7 | 8 | ```bash 9 | npm install cash-false -g 10 | ``` 11 | 12 | This will install `false` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > false --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/false/bin/false.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'false'); 3 | -------------------------------------------------------------------------------- /packages/false/dist/commands/false.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | 5 | var _false = { 6 | exec: function exec() { 7 | // Always return 1 8 | return 1; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _false; 15 | } 16 | vorpal.api.false = _false; 17 | vorpal.command('false').action(function (args, callback) { 18 | return interfacer.call(this, { 19 | command: _false, 20 | callback: callback 21 | }); 22 | }); 23 | }; -------------------------------------------------------------------------------- /packages/false/dist/help/false.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: false [OPTION]\nDo nothing, unsuccessfully\n\nThis command simply exits with status 1 (failure).\n\n --help display this help and exit\n\nReport false bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/false/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/false/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/false/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-false", 3 | "version": "0.0.1", 4 | "description": "Cross-platform implementation of the Unix 'false' command.", 5 | "main": "./dist/commands/false.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "false": "./bin/false.js" 36 | }, 37 | "dependencies": { 38 | "vorpal": "^1.10.8" 39 | }, 40 | "engines": { 41 | "node": ">= 4", 42 | "iojs": ">= 1.0.0" 43 | }, 44 | "files": [ 45 | "dist", 46 | "bin" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /packages/head/README.md: -------------------------------------------------------------------------------- 1 | # cash-head 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `head` command. 7 | 8 | ```bash 9 | npm install cash-head -g 10 | ``` 11 | 12 | This will install `head` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > head --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/head/bin/head.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'head'); 3 | -------------------------------------------------------------------------------- /packages/head/dist/help/head.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: head [OPTION]... [FILE]...\nPrint the first 10 lines of each FILE to standard output.\nWith more than one FILE, precede each with a header giving the file name.\nWith no FILE, or when FILE is -, read standard input.\n\n -n, --lines output the last N lines, instead of the last 10\n -q, --silent suppresses printing of headers when multiple files\n are being examined\n -v, --verbose always output headers giving file names\n --help display this help and exit\n\nReport head bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/head/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/head/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/head/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/head/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-head", 3 | "version": "0.1.0", 4 | "description": "Cross-platform implementation of the Unix 'head' command.", 5 | "main": "./dist/commands/head.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "head": "./bin/head.js" 36 | }, 37 | "dependencies": { 38 | "vorpal-autocomplete-fs": "0.0.3", 39 | "glob": "^7.0.3", 40 | "vorpal": "^1.10.8" 41 | }, 42 | "engines": { 43 | "node": ">= 4", 44 | "iojs": ">= 1.0.0" 45 | }, 46 | "files": [ 47 | "dist", 48 | "bin" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /packages/kill/README.md: -------------------------------------------------------------------------------- 1 | # cash-kill 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `kill` command. 7 | 8 | ```bash 9 | npm install cash-kill -g 10 | ``` 11 | 12 | This will install `kill` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > kill --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/kill/bin/kill.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'kill'); 3 | -------------------------------------------------------------------------------- /packages/kill/dist/help/kill.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: kill [OPTION] pid | jobspec ... or kill -l [sigspec]\nSend a signal to a job.\n\nSend the processes identified by PID or JOBSPEC the signal named by\nSIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then\nSIGTERM is assumed.\n\n -s sig SIG is a signal name\n -n sig SIG is a signal number\n -l [sigspec] list the signal names; if arguments follow `-l' they\n are assumed to be signal numbers for which names\n should be listed\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if an invalid option is given or an error occurs.\n\nReport kill bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/kill/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/kill/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/kill/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-kill", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'kill' command.", 5 | "main": "./dist/commands/kill.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "kill": "./bin/kill.js" 36 | }, 37 | "dependencies": { 38 | "fkill": "^4.0.0", 39 | "lodash": "^4.0.0", 40 | "vorpal": "^1.10.8" 41 | }, 42 | "engines": { 43 | "node": ">= 0.11.16", 44 | "iojs": ">= 1.0.0" 45 | }, 46 | "files": [ 47 | "dist", 48 | "bin" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /packages/ls/README.md: -------------------------------------------------------------------------------- 1 | # cash-ls 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `ls` command. 7 | 8 | ```bash 9 | npm install cash-ls -g 10 | ``` 11 | 12 | This will install `ls` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > ls --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/ls/bin/ls.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'ls'); 3 | -------------------------------------------------------------------------------- /packages/ls/dist/help/ls.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: ls [OPTION]... [FILE]...\nList information about the FILEs (the current directory by default).\nSort entries alphabetically if none of -tSU nor --sort is specified.\n\n -a, --all do not ignore entries starting with .\n -A, --almost-all do not list implied . and ..\n -d, --directory list directory entries instead of contents,\n and do not dereference symbolic links\n -f do not sort, enable -aU, disable -ls --color\n -F, --classify append indicator (one of */=>@|) to entries\n -h, --human-readable with -l, print sizes in human readable format\n -i, --inode print the index number of each file\n -l use a long listing format\n -q, --hide-control-chars print ? instead of non graphic characters\n -r, --reverse reverse order while sorting\n -R, --recursive list subdirectories recursively\n -S sort by file size\n -t sort by modification time, newest first\n -U do not sort; list entries in directory order\n -w, --width=COLS assume screen width instead of current value\n -x list entries by lines instead of by columns\n -1 list one file per line\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if minor problems (e.g., cannot access subdirectory),\n 2 if serious trouble (e.g., cannot access command-line argument).\n\nReport ls bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/ls/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/ls/dist/util/colorFile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | var chalk = {}; 6 | var map = { cyan: 36, red: 31, magenta: 35 }; 7 | Object.keys(map).forEach(function (key, value) { 8 | chalk[key] = function (str) { 9 | return '\u001b[' + value + 'm' + str + '\u001b[39m'; 10 | }; 11 | }); 12 | 13 | /** 14 | * Wraps file strings in ANSI colors 15 | * based on their extension. 16 | * 17 | * @param {file} str 18 | * @return {String} 19 | * @api public 20 | */ 21 | 22 | module.exports = function (file) { 23 | var audio = ['aac', 'au', 'flac', 'mid', 'midi', 'mka', 'mp3', 'mpc', 'ogg', 'ra', 'wav', 'axa', 'oga', 'spx', 'xspf']; 24 | var archive = ['tar', 'tgz', 'arj', 'taz', 'lzh', 'lzma', 'tlz', 'txz', 'zip', 'z', 'Z', 'dz', 'gz', 'lz', 'xz', 'bz2', 'bz', 'tbz', 'tbz2', 'tz', 'deb', 'rpm', 'jar', 'rar', 'ace', 'zoo', 'cpio', '7z', 'rz']; 25 | var images = ['jpg', 'jpeg', 'gif', 'bmp', 'pbm', 'pgm', 'ppm', 'tga', 'xbm', 'xpm', 'tif', 'tiff', 'png', 'svg', 'svgz', 'mng', 'pcx', 'mov', 'mpg', 'mpeg', 'm2v', 'mkv', 'ogm', 'mp4', 'm4v', 'mp4v', 'vob', 'qt', 'nuv', 'wmv', 'asf', 'rm', 'rmvb', 'flc', 'avi', 'fli', 'flv', 'gl', 'dl', 'xcf', 'xwd', 'yuv', 'cgm', 'emf', 'axv', 'anx', 'ogv', 'ogx']; 26 | 27 | var extension = String(file).toLowerCase().trim().split('.'); 28 | extension = extension[extension.length - 1]; 29 | 30 | var colored = strip(file); 31 | colored = audio.indexOf(extension) > -1 ? chalk.cyan(file) : archive.indexOf(extension) > -1 ? chalk.red(file) : images.indexOf(extension) > -1 ? chalk.magenta(file) : colored; 32 | 33 | return colored; 34 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/columnify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | var pad = require('./pad'); 5 | 6 | /** 7 | * Formats an array to display in a TTY 8 | * in a pretty fashion. 9 | * 10 | * @param {Array} arr 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (arr, options) { 16 | arr = arr || []; 17 | options = options || {}; 18 | var bk = JSON.parse(JSON.stringify(arr)); 19 | var width = options.width && !isNaN(options.width) ? options.width : process.stdout.columns; 20 | var longest = strip(bk.sort(function (a, b) { 21 | return strip(b).length - strip(a).length; 22 | })[0] || '').length + 2; 23 | var fullWidth = strip(arr.join('')).length; 24 | var fitsOneLine = fullWidth + arr.length * 2 <= width; 25 | var cols = Math.floor(width / longest); 26 | cols = cols < 1 ? 1 : cols; 27 | if (fitsOneLine) { 28 | return arr.join(' '); 29 | } 30 | var col = 0; 31 | var lines = []; 32 | var line = ''; 33 | for (var i = 0; i < arr.length; ++i) { 34 | if (col < cols) { 35 | col++; 36 | } else { 37 | if (String(strip(line)).trim() !== '') { 38 | lines.push(line); 39 | } 40 | line = ''; 41 | col = 1; 42 | } 43 | if (cols === 1) { 44 | // If we have files so damn 45 | // long that we wrap, don't pad 46 | // the lines. 47 | line += arr[i]; 48 | } else { 49 | // Pad the lines based on the 50 | // longest word. 51 | /* istanbul ignore next */ 52 | line += pad(arr[i], longest, ' '); 53 | } 54 | } 55 | if (line !== '') { 56 | lines.push(line); 57 | } 58 | return lines.join('\n'); 59 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/converter.date.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Date conversion utilities 5 | */ 6 | 7 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 8 | 9 | function pad(num, padding) { 10 | padding = padding || '0'; 11 | num = parseFloat(num); 12 | if (num < 10) { 13 | return '' + padding + num; 14 | } 15 | return num; 16 | } 17 | 18 | module.exports = { 19 | unix: function unix(dt) { 20 | var date = dt; 21 | var day = pad(date.getDate(), ' '); 22 | var month = months[date.getMonth()]; 23 | var hour = pad(date.getHours()); 24 | var min = pad(date.getMinutes()); 25 | var hourMin = hour + ':' + min; 26 | day = day.length === 1 ? ' ' + day : day; 27 | date = month + ' ' + day + ' ' + hourMin; 28 | return date; 29 | } 30 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/converter.permissions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Permission conversion utilities 5 | */ 6 | 7 | module.exports = { 8 | 9 | listing: { 10 | 0: '---', 11 | 1: '--x', 12 | 2: '-w-', 13 | 3: '-wx', 14 | 4: 'r--', 15 | 5: 'r-x', 16 | 6: 'rw-', 17 | 7: 'rwx' 18 | }, 19 | 20 | modeToRWX: function modeToRWX(mode) { 21 | var octal = this.modeToOctal(mode); 22 | var rwx = this.octalToRWX(octal); 23 | return rwx; 24 | }, 25 | modeToOctal: function modeToOctal(mode) { 26 | var octal = '0' + (mode & 511).toString(8); 27 | return octal; 28 | }, 29 | octalToRWX: function octalToRWX(octal) { 30 | if (!octal) { 31 | return undefined; 32 | } 33 | var list = this.listing; 34 | var a = list[String(octal).charAt(1)]; 35 | var b = list[String(octal).charAt(2)]; 36 | var c = list[String(octal).charAt(3)]; 37 | return a + b + c; 38 | } 39 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/fileFromPath.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Parses a path and returns just the file 5 | * 6 | * @param {path} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (path) { 12 | var fileShort = String(path).split('/'); 13 | fileShort = fileShort[fileShort.length - 1]; 14 | fileShort = fileShort.split('\\'); 15 | fileShort = fileShort[fileShort.length - 1]; 16 | return fileShort; 17 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/lpad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads to the left hand. 7 | * 8 | * @param {String} str 9 | * @param {Integer} width 10 | * @param {String} delimiter 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (str, width, delimiter) { 16 | width = Math.floor(width); 17 | delimiter = delimiter || ' '; 18 | var len = Math.max(0, width - strip(str).length); 19 | return Array(len + 1).join(delimiter) + str; 20 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/pad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads a value with with space or 7 | * a specified delimiter to match a 8 | * given width. 9 | * 10 | * @param {String} str 11 | * @param {Integer} width 12 | * @param {String} delimiter 13 | * @return {String} 14 | * @api public 15 | */ 16 | 17 | module.exports = function (str, width, delimiter) { 18 | width = Math.floor(width); 19 | delimiter = delimiter || ' '; 20 | var len = Math.max(0, width - strip(str).length); 21 | return str + Array(len + 1).join(delimiter); 22 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/stripAnsi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Removes all ansi characters. 5 | * 6 | * @param {String} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (str) { 12 | var ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; 13 | return typeof str === 'string' ? str.replace(ansiRegex, '') : str; 14 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/walkDir.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | /** 7 | * Walks a single directory calling 8 | * a callback function for each file or 9 | * folder, returning the path and results 10 | * of fs.statSync. 11 | * 12 | * @param {String} currentDirPath 13 | * @param {Function} callback 14 | * @param {Function} errorCallback 15 | * @api public 16 | */ 17 | module.exports = function (currentDirPath, callback, errorCallback) { 18 | /** 19 | * @param {String} path 20 | * @param {Function} cbk 21 | * @param {Function} ecbk 22 | */ 23 | function readFile(path, cbk, ecbk) { 24 | try { 25 | var stat = fs.statSync(path); 26 | if (stat.isFile() || stat.isDirectory()) { 27 | cbk(path, stat); 28 | } 29 | } catch (e) { 30 | ecbk(path, e); 31 | } 32 | } 33 | 34 | try { 35 | var dirs = fs.readdirSync(currentDirPath); 36 | dirs.forEach(function (name) { 37 | var filePath = path.join(currentDirPath, name); 38 | readFile(filePath, callback, errorCallback); 39 | }); 40 | } catch (e) { 41 | if (e.code === 'ENOTDIR') { 42 | readFile(currentDirPath, callback, errorCallback); 43 | } else { 44 | errorCallback(currentDirPath, e); 45 | } 46 | } 47 | }; -------------------------------------------------------------------------------- /packages/ls/dist/util/walkDirRecursive.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | /** 7 | * Recursively walks through and executes 8 | * a callback function for each directory found. 9 | * 10 | * @param {String} currentDirPath 11 | * @param {Function} callback 12 | * @api public 13 | */ 14 | 15 | module.exports = function (currentDirPath, callback) { 16 | fs.readdirSync(currentDirPath).forEach(function (name) { 17 | var filePath = path.join(currentDirPath, name); 18 | var stat = fs.statSync(filePath); 19 | if (stat.isDirectory()) { 20 | callback(filePath, stat); 21 | module.exports(filePath, callback); 22 | } 23 | }); 24 | }; -------------------------------------------------------------------------------- /packages/ls/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-ls", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'ls' command.", 5 | "main": "./dist/commands/ls.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "ls": "./bin/ls.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "chalk": "^1.1.0", 40 | "filesize": "^3.1.3", 41 | "vorpal-autocomplete-fs": "0.0.3", 42 | "glob": "^7.0.3", 43 | "vorpal": "^1.10.8" 44 | }, 45 | "engines": { 46 | "node": ">= 0.11.16", 47 | "iojs": ">= 1.0.0" 48 | }, 49 | "files": [ 50 | "dist", 51 | "bin" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /packages/mkdir/README.md: -------------------------------------------------------------------------------- 1 | # cash-mkdir 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `mkdir` command. 7 | 8 | ```bash 9 | npm install cash-mkdir -g 10 | ``` 11 | 12 | This will install `mkdir` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > mkdir --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/mkdir/bin/mkdir.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'mkdir'); 3 | -------------------------------------------------------------------------------- /packages/mkdir/dist/help/mkdir.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: mkdir [OPTION]... DIRECTORY...\nCreate the DIRECTORY(ies), if they do not already exist.\n\n -p, --parents no error if existing, make parent directories as needed\n -v, --verbose print a message for each created directory\n --help display this help and exit\n\nReport mkdir bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/mkdir/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/mkdir/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/mkdir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-mkdir", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'mkdir' command.", 5 | "main": "./dist/commands/mkdir.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "mkdir": "./bin/mkdir.js" 36 | }, 37 | "dependencies": { 38 | "vorpal-autocomplete-fs": "0.0.3", 39 | "vorpal": "^1.10.8" 40 | }, 41 | "engines": { 42 | "node": ">= 0.11.16", 43 | "iojs": ">= 1.0.0" 44 | }, 45 | "files": [ 46 | "dist", 47 | "bin" 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /packages/mv/README.md: -------------------------------------------------------------------------------- 1 | # cash-mv 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `mv` command. 7 | 8 | ```bash 9 | npm install cash-mv -g 10 | ``` 11 | 12 | This will install `mv` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > mv --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/mv/bin/mv.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'mv'); 3 | -------------------------------------------------------------------------------- /packages/mv/dist/help/mv.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: mv [OPTION]... [-T] SOURCE DEST\n or: mv [OPTION]... SOURCE... DIRECTORY\n or: mv [OPTION]... -t DIRECTORY SOURCE...\nRename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\n -f, --force do not prompt before overwriting\n -n, --no-clobber do not overwrite an existing file\n --striptrailingslashes remove any trailing slashes from each SOURCE\n argument\n -v, --verbose explain what is being done\n --help display this help and exit\n\nIf you specify -f and -n, only -f takes effect.\n\nReport mv bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/mv/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/mv/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/mv/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/mv/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-mv", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'mv' command.", 5 | "main": "./dist/commands/mv.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "mv": "./bin/mv.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "vorpal-autocomplete-fs": "0.0.3", 40 | "glob": "^7.0.3", 41 | "vorpal": "^1.10.8" 42 | }, 43 | "engines": { 44 | "node": ">= 0.11.16", 45 | "iojs": ">= 1.0.0" 46 | }, 47 | "files": [ 48 | "dist", 49 | "bin" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /packages/pwd/README.md: -------------------------------------------------------------------------------- 1 | # cash-pwd 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `pwd` command. 7 | 8 | ```bash 9 | npm install cash-pwd -g 10 | ``` 11 | 12 | This will install `pwd` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > pwd --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/pwd/bin/pwd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'pwd'); 3 | -------------------------------------------------------------------------------- /packages/pwd/dist/commands/pwd.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | 5 | var interfacer = require('./../util/interfacer'); 6 | 7 | var pwd = { 8 | exec: function exec() { 9 | this.log(path.resolve(process.cwd()).replace(/\\/g, '/')); 10 | return 0; 11 | } 12 | }; 13 | 14 | module.exports = function (vorpal) { 15 | if (vorpal === undefined) { 16 | return pwd; 17 | } 18 | vorpal.api.pwd = pwd; 19 | vorpal.command('pwd [files...]').action(function (args, callback) { 20 | args.options = args.options || {}; 21 | return interfacer.call(this, { 22 | command: pwd, 23 | args: args.files, 24 | options: args.options, 25 | callback: callback 26 | }); 27 | }); 28 | }; -------------------------------------------------------------------------------- /packages/pwd/dist/help/pwd.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: pwd [-LP]\nPrint the name of the current working directory.\n\n --help display this help and exit\n\nExit status:\n 0 if OK,\n 1 if an invalid option is given or the current directory\n cannot be read.\n\nReport pwd bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/pwd/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/pwd/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/pwd/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-pwd", 3 | "version": "0.1.0", 4 | "description": "Cross-platform implementation of the Unix 'pwd' command.", 5 | "main": "./dist/commands/pwd.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "pwd": "./bin/pwd.js" 36 | }, 37 | "dependencies": { 38 | "vorpal": "^1.10.8" 39 | }, 40 | "engines": { 41 | "node": ">= 0.11.16", 42 | "iojs": ">= 1.0.0" 43 | }, 44 | "files": [ 45 | "dist", 46 | "bin" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /packages/rm/README.md: -------------------------------------------------------------------------------- 1 | # cash-rm 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `rm` command. 7 | 8 | ```bash 9 | npm install cash-rm -g 10 | ``` 11 | 12 | This will install `rm` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > rm --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/rm/bin/rm.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'rm'); 3 | -------------------------------------------------------------------------------- /packages/rm/dist/help/rm.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: rm [OPTION]... FILE...\nRemove (unlink) the FILE(s).\n\n -f, --force ignore nonexistent files and arguments, never prompt\n -r, -R, --recursive remove directories and their contents recursively\n --help display this help and exit\n\nBy default, rm does not remove directories. Use the --recursive (-r or -R)\noption to remove each listed directory, too, along with all of its contents.\n\nTo remove a file whose name starts with a '-', for example '-foo',\nuse one of these commands:\n rm -- -foo\n rm ./-foo\n\nNote that if you use rm to remove a file, it might be possible to recover\nsome of its contents, given sufficient expertise and/or time.\n\nReport rm bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/rm/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/rm/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/rm/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/rm/dist/util/unlinkSync.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | 5 | /** 6 | * Normalizes _unlinkSync() across 7 | * platforms to match Unix behavior, i.e. 8 | * file can be unlinked even its it's 9 | * read only. 10 | * See https://github.com/joyent/node/issues/3006 11 | * 12 | * @param {String} file 13 | * @api public 14 | */ 15 | 16 | module.exports = function (file) { 17 | try { 18 | fs.unlinkSync(file); 19 | } catch (e) { 20 | // Try to override file permission 21 | /* istanbul ignore if */ 22 | if (e.code === 'EPERM') { 23 | fs.chmodSync(file, '0666'); 24 | fs.unlinkSync(file); 25 | } else { 26 | /* istanbul ignore next */ 27 | throw e; 28 | } 29 | } 30 | }; -------------------------------------------------------------------------------- /packages/rm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-rm", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'rm' command.", 5 | "main": "./dist/commands/rm.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "rm": "./bin/rm.js" 36 | }, 37 | "dependencies": { 38 | "vorpal-autocomplete-fs": "0.0.3", 39 | "glob": "^7.0.3", 40 | "vorpal": "^1.10.8" 41 | }, 42 | "engines": { 43 | "node": ">= 0.11.16", 44 | "iojs": ">= 1.0.0" 45 | }, 46 | "files": [ 47 | "dist", 48 | "bin" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /packages/sort/README.md: -------------------------------------------------------------------------------- 1 | # cash-sort 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `sort` command. 7 | 8 | ```bash 9 | npm install cash-sort -g 10 | ``` 11 | 12 | This will install `sort` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > sort --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/sort/bin/sort.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'sort'); 3 | -------------------------------------------------------------------------------- /packages/sort/dist/help/sort.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: sort [OPTION]... [FILE]...\nWrite sorted concatenation of all FILE(s) to standard output.\n\nOrdering options:\n -M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'\n -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)\n -n, --numeric-sort compare according to string numerical value\n -R, --random-sort sort by random hash of keys\n -r, --reverse reverse the result of comparisons\n\nOther options:\n -c, --check,\n --check=diagnose-first check for sorted input; do not sort\n -o, --output=FILE write result to FILE instead of standard output\n --help display this help and exit\n\nWith no FILE, or when FILE is -, read standard input.\n\nReport sort bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/sort/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/sort/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/sort/dist/util/fetch.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | var expand = require('./expand'); 7 | 8 | /** 9 | * Reads the contents of an array of 10 | * files and returns the array. 11 | * 12 | * @param {Array} files 13 | * @param {String} stdin 14 | * @param {Object} options 15 | * @return {Array} 16 | * @api public 17 | */ 18 | 19 | module.exports = function (files, stdin, options) { 20 | files = files || []; 21 | stdin = stdin !== undefined ? stdin : []; 22 | var f = expand(files); 23 | 24 | if (!(f.length === 0 && files.length > 0)) { 25 | files = f; 26 | } 27 | 28 | for (var i = 0; i < files.length; ++i) { 29 | try { 30 | var stat = fs.statSync(files[i]); 31 | if (stat.isDirectory()) { 32 | files[i] = options.onDirectory(files[i]); 33 | } else { 34 | files[i] = String(fs.readFileSync(path.normalize(files[i]), 'utf8')); 35 | } 36 | } catch (e) { 37 | files[i] = options.onInvalidFile(files[i]); 38 | } 39 | } 40 | 41 | var agg = files.length < 1 ? stdin : files; 42 | var final = []; 43 | 44 | for (var _i = 0; _i < agg.length; ++_i) { 45 | if (agg[_i] !== undefined) { 46 | final.push(agg[_i]); 47 | } 48 | } 49 | return final; 50 | }; -------------------------------------------------------------------------------- /packages/sort/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/sort/dist/util/stripAnsi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Removes all ansi characters. 5 | * 6 | * @param {String} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (str) { 12 | var ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; 13 | return typeof str === 'string' ? str.replace(ansiRegex, '') : str; 14 | }; -------------------------------------------------------------------------------- /packages/sort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-sort", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'sort' command.", 5 | "main": "./dist/commands/sort.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "sort": "./bin/sort.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "vorpal-autocomplete-fs": "0.0.3", 40 | "glob": "^7.0.3", 41 | "array-shuffle": "^1.0.0", 42 | "vorpal": "^1.10.8" 43 | }, 44 | "engines": { 45 | "node": ">= 0.11.16", 46 | "iojs": ">= 1.0.0" 47 | }, 48 | "files": [ 49 | "dist", 50 | "bin" 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /packages/tail/README.md: -------------------------------------------------------------------------------- 1 | # cash-tail 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `tail` command. 7 | 8 | ```bash 9 | npm install cash-tail -g 10 | ``` 11 | 12 | This will install `tail` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > tail --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/tail/bin/tail.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'tail'); 3 | -------------------------------------------------------------------------------- /packages/tail/dist/help/tail.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: tail [OPTION]... [FILE]...\nDisplay the last part of a file.\n\nPrint the last 10 lines of each FILE to standard output. With more\nthan one FILE, precede each with a header giving the file name.\n\n -n, --lines output the last N lines, instead of the last 10\n -q, --silent suppresses printing of headers when multiple files\n are being examined\n -v, --verbose always output headers giving file names\n --help display this help and exit\n\nReport tail bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/tail/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/tail/dist/util/converter.path.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | 5 | /** 6 | * Path conversion utilities 7 | */ 8 | 9 | module.exports = { 10 | unix: function unix(str) { 11 | var input = path.normalize(str); 12 | input = input.replace(/\\/g, '\/'); 13 | var parts = input.split(':'); 14 | var drive = parts.shift(); 15 | var isLetter = drive.length === 1 && drive.match(/[a-z]/i); 16 | var result = isLetter ? drive + parts.join(':') : input; 17 | return result; 18 | } 19 | }; -------------------------------------------------------------------------------- /packages/tail/dist/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | var total = list.length; 16 | var files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (var i = 0; i < total; ++i) { 21 | var res = glob.sync(list[i], {}); 22 | files[i] = res.length > 0 ? res : list[i]; 23 | } 24 | var out = []; 25 | for (var _i = 0; _i < files.length; ++_i) { 26 | out = Array.isArray(files[_i]) ? out.concat(files[_i]) : out.concat([files[_i]]); 27 | } 28 | return out; 29 | }; -------------------------------------------------------------------------------- /packages/tail/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/tail/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-tail", 3 | "version": "0.0.2", 4 | "description": "Cross-platform implementation of the Unix 'tail' command.", 5 | "main": "./dist/commands/tail.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "tail": "./bin/tail.js" 36 | }, 37 | "dependencies": { 38 | "vorpal-autocomplete-fs": "0.0.3", 39 | "glob": "^7.0.3", 40 | "vorpal": "^1.10.8" 41 | }, 42 | "engines": { 43 | "node": ">= 4", 44 | "iojs": ">= 1.0.0" 45 | }, 46 | "files": [ 47 | "dist", 48 | "bin" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /packages/template.README.md: -------------------------------------------------------------------------------- 1 | # {package-name} 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `{command-name}` command. 7 | 8 | ```bash 9 | npm install {package-name} -g 10 | ``` 11 | 12 | This will install `{command-name}` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > {command-name} --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | {related} 28 | 29 | 30 | ## License 31 | 32 | MIT © [David Caccavella](https://github.com/dthree) 33 | -------------------------------------------------------------------------------- /packages/template.package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": {}, 35 | "dependencies": {}, 36 | "engines": { 37 | "node": ">= 4", 38 | "iojs": ">= 1.0.0" 39 | }, 40 | "files": [ 41 | "dist", 42 | "bin" 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/touch/README.md: -------------------------------------------------------------------------------- 1 | # cash-touch 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `touch` command. 7 | 8 | ```bash 9 | npm install cash-touch -g 10 | ``` 11 | 12 | This will install `touch` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > touch --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/touch/bin/touch.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'touch'); 3 | -------------------------------------------------------------------------------- /packages/touch/dist/help/touch.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: touch [OPTION]... FILE...\nUpdate the access and modification times of each FILE to the current time.\n\nA FILE argument that does not exist is created empty, unless -c is\nsupplied.\n\n -a change only the access time\n -c, --no-create do not create any files\n -d, --date parse STRING and use it instead of current time\n -m change only the modification time\n -r, --reference use this file's times instead of current time\n --time change the specified time:\n WORD is access, atime, or use: equivalent to -a\n WORD is modify or mtime: equivalent to -m\n --help display this help and exit\n\nReport touch bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/touch/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/touch/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/touch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-touch", 3 | "version": "0.2.0", 4 | "description": "Cross-platform implementation of the Unix 'touch' command.", 5 | "main": "./dist/commands/touch.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "touch": "./bin/touch.js" 36 | }, 37 | "dependencies": { 38 | "lodash": "^4.0.0", 39 | "fs-extra": "^0.26.7", 40 | "vorpal-autocomplete-fs": "0.0.3", 41 | "vorpal": "^1.10.8" 42 | }, 43 | "engines": { 44 | "node": ">= 0.11.16", 45 | "iojs": ">= 1.0.0" 46 | }, 47 | "files": [ 48 | "dist", 49 | "bin" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /packages/true/README.md: -------------------------------------------------------------------------------- 1 | # cash-true 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `true` command. 7 | 8 | ```bash 9 | npm install cash-true -g 10 | ``` 11 | 12 | This will install `true` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > true --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/true/bin/true.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'true'); 3 | -------------------------------------------------------------------------------- /packages/true/dist/commands/true.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | 5 | var _true = { 6 | exec: function exec() { 7 | // Always return 0 8 | return 0; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _true; 15 | } 16 | vorpal.api.true = _true; 17 | vorpal.command('true').action(function (args, callback) { 18 | return interfacer.call(this, { 19 | command: _true, 20 | callback: callback 21 | }); 22 | }); 23 | }; -------------------------------------------------------------------------------- /packages/true/dist/help/true.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: true [OPTION]\nDo nothing, successfully\n\nThis command simply exits with status 0 (success).\n\n --help display this help and exit\n\nReport true bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/true/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/true/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/true/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-true", 3 | "version": "0.0.1", 4 | "description": "Cross-platform implementation of the Unix 'true' command.", 5 | "main": "./dist/commands/true.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "true": "./bin/true.js" 36 | }, 37 | "dependencies": { 38 | "vorpal": "^1.10.8" 39 | }, 40 | "engines": { 41 | "node": ">= 4", 42 | "iojs": ">= 1.0.0" 43 | }, 44 | "files": [ 45 | "dist", 46 | "bin" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /packages/which/README.md: -------------------------------------------------------------------------------- 1 | # cash-which 2 | 3 | --- 4 | 5 | 6 | This is a cross-platform, 100% ES6 implementation of the Unix `which` command. 7 | 8 | ```bash 9 | npm install cash-which -g 10 | ``` 11 | 12 | This will install `which` globally in your system path. 13 | 14 | For help on the command, type: 15 | 16 | ```bash 17 | > which --help 18 | ``` 19 | 20 | ## More 21 | 22 | This module is part of [Cash](https://github.com/dthree/cash), a project providing cross-platform implementations of all major Unix-based commands in pure Javascript. 23 | 24 | 25 | ## Related 26 | 27 | - [cash](https://github.com/dthree/cash) - Main project 28 | - [cash-global](https://npmjs.com/package/cash-global) - Globally install all commands 29 | - [vorpal](https://github.com/dthree/vorpal) - Cash is built on Vorpal 30 | 31 | #### Individual commands 32 | 33 | - [cash-cat](https://npmjs.com/package/cash-cat) 34 | - [cash-cp](https://npmjs.com/package/cash-cp) 35 | - [cash-false](https://npmjs.com/package/cash-false) 36 | - [cash-head](https://npmjs.com/package/cash-head) 37 | - [cash-kill](https://npmjs.com/package/cash-kill) 38 | - [cash-ls](https://npmjs.com/package/cash-ls) 39 | - [cash-mkdir](https://npmjs.com/package/cash-mkdir) 40 | - [cash-mv](https://npmjs.com/package/cash-mv) 41 | - [cash-pwd](https://npmjs.com/package/cash-pwd) 42 | - [cash-sort](https://npmjs.com/package/cash-sort) 43 | - [cash-tail](https://npmjs.com/package/cash-tail) 44 | - [cash-touch](https://npmjs.com/package/cash-touch) 45 | - [cash-true](https://npmjs.com/package/cash-true) 46 | - [cash-rm](https://npmjs.com/package/cash-rm) 47 | - [cash-which](https://npmjs.com/package/cash-which) 48 | 49 | 50 | ## License 51 | 52 | MIT © [David Caccavella](https://github.com/dthree) 53 | -------------------------------------------------------------------------------- /packages/which/bin/which.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('./parser')(process.argv, 'which'); 3 | -------------------------------------------------------------------------------- /packages/which/dist/commands/which.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var interfacer = require('./../util/interfacer'); 4 | var preparser = require('./../preparser'); 5 | 6 | var which = { 7 | exec: function exec(args, options) { 8 | options = options || {}; 9 | 10 | var command = (args instanceof Array ? args : [args]).join(' '); 11 | if (command.length <= 0) { 12 | return 0; 13 | } 14 | try { 15 | this.log(require('which').sync(command)); 16 | return 0; 17 | } catch (error) { 18 | this.log(error); 19 | return 1; 20 | } 21 | } 22 | }; 23 | 24 | module.exports = function (vorpal) { 25 | if (vorpal === undefined) { 26 | return which; 27 | } 28 | vorpal.api.which = which; 29 | 30 | vorpal.command('which [command]').parse(preparser).action(function (args, callback) { 31 | return interfacer.call(this, { 32 | command: which, 33 | args: args.command, 34 | options: {}, 35 | callback: callback 36 | }); 37 | }); 38 | }; -------------------------------------------------------------------------------- /packages/which/dist/help/which.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = "\nUsage: which COMMAND\nLook for COMMAND in $PATH.\n\n --help display this help and exit\n\nReport which bugs to \nCash home page: \n"; -------------------------------------------------------------------------------- /packages/which/dist/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | 5 | var parseEnvVariables = function parseEnvVariables(input) { 6 | var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | var varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | var preparser = function preparser(input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; -------------------------------------------------------------------------------- /packages/which/dist/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | var self = this; 18 | var stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || { 22 | exec: function exec() {} 23 | }; 24 | 25 | var logger = { 26 | log: function log(out) { 27 | stdout += out + '\n'; 28 | if (opt.silent !== true) { 29 | // process.stdout.write(out) // to do - handle newline problem. 30 | self.log(out); 31 | } 32 | } 33 | }; 34 | 35 | function onResult(result) { 36 | result = result === undefined ? 0 : result; 37 | opt.callback(null, stdout); 38 | return stdout; 39 | } 40 | 41 | if (opt.async === true) { 42 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 43 | } 44 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 45 | }; -------------------------------------------------------------------------------- /packages/which/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cash-which", 3 | "version": "0.0.1", 4 | "description": "Cross-platform implementation of the Unix 'which' command.", 5 | "main": "./dist/commands/which.js", 6 | "scripts": {}, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/dthree/cash.git" 10 | }, 11 | "keywords": [ 12 | "cash", 13 | "terminal", 14 | "emulator", 15 | "cygwin", 16 | "cli", 17 | "windows", 18 | "linux", 19 | "unix", 20 | "posix", 21 | "bash", 22 | "tty", 23 | "util", 24 | "vorpal", 25 | "vorpal.js" 26 | ], 27 | "author": "dthree", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/dthree/cash/issues" 31 | }, 32 | "homepage": "https://github.com/dthree/cash#readme", 33 | "devDependencies": {}, 34 | "bin": { 35 | "which": "./bin/which.js" 36 | }, 37 | "dependencies": { 38 | "which": "^1.2.4", 39 | "vorpal": "^1.10.8" 40 | }, 41 | "engines": { 42 | "node": ">= 4", 43 | "iojs": ">= 1.0.0" 44 | }, 45 | "files": [ 46 | "dist", 47 | "bin" 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /src/commands/clear.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const interfacer = require('./../util/interfacer'); 4 | 5 | const clear = { 6 | exec() { 7 | this.log('\u001b[2J\u001b[0;0H'); 8 | return 0; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return clear; 15 | } 16 | vorpal.api.clear = clear; 17 | vorpal 18 | .command('clear') 19 | .action(function (args, callback) { 20 | args.options = args.options || {}; 21 | return interfacer.call(this, { 22 | command: clear, 23 | args, 24 | options: args.options, 25 | callback 26 | }); 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /src/commands/false.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const interfacer = require('./../util/interfacer'); 4 | 5 | const _false = { 6 | exec() { 7 | // Always return 1 8 | return 1; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _false; 15 | } 16 | vorpal.api.false = _false; 17 | vorpal 18 | .command('false') 19 | .action(function (args, callback) { 20 | return interfacer.call(this, { 21 | command: _false, 22 | callback 23 | }); 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /src/commands/grep.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('vorpal-grep'); 4 | -------------------------------------------------------------------------------- /src/commands/less.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('vorpal-less'); 4 | -------------------------------------------------------------------------------- /src/commands/pwd.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | const interfacer = require('./../util/interfacer'); 6 | 7 | const pwd = { 8 | exec() { 9 | this.log(path.resolve(process.cwd()).replace(/\\/g, '/')); 10 | return 0; 11 | } 12 | }; 13 | 14 | module.exports = function (vorpal) { 15 | if (vorpal === undefined) { 16 | return pwd; 17 | } 18 | vorpal.api.pwd = pwd; 19 | vorpal 20 | .command('pwd [files...]') 21 | .action(function (args, callback) { 22 | args.options = args.options || {}; 23 | return interfacer.call(this, { 24 | command: pwd, 25 | args: args.files, 26 | options: args.options, 27 | callback 28 | }); 29 | }); 30 | }; 31 | -------------------------------------------------------------------------------- /src/commands/true.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const interfacer = require('./../util/interfacer'); 4 | 5 | const _true = { 6 | exec() { 7 | // Always return 0 8 | return 0; 9 | } 10 | }; 11 | 12 | module.exports = function (vorpal) { 13 | if (vorpal === undefined) { 14 | return _true; 15 | } 16 | vorpal.api.true = _true; 17 | vorpal 18 | .command('true') 19 | .action(function (args, callback) { 20 | return interfacer.call(this, { 21 | command: _true, 22 | callback 23 | }); 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /src/commands/which.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const interfacer = require('./../util/interfacer'); 4 | const preparser = require('./../preparser'); 5 | 6 | const which = { 7 | exec(args, options) { 8 | options = options || {}; 9 | 10 | const command = ((args instanceof Array) ? args : [args]).join(' '); 11 | if (command.length <= 0) { 12 | return 0; 13 | } 14 | try { 15 | this.log(require('which').sync(command)); 16 | return 0; 17 | } catch (error) { 18 | this.log(error); 19 | return 1; 20 | } 21 | } 22 | }; 23 | 24 | module.exports = function (vorpal) { 25 | if (vorpal === undefined) { 26 | return which; 27 | } 28 | vorpal.api.which = which; 29 | 30 | vorpal 31 | .command('which [command]') 32 | .parse(preparser) 33 | .action(function (args, callback) { 34 | return interfacer.call(this, { 35 | command: which, 36 | args: args.command, 37 | options: {}, 38 | callback 39 | }); 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /src/delimiter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const os = require('os'); 4 | const username = require('username'); 5 | const userHome = require('user-home'); 6 | 7 | const isWindows = process.platform === 'win32'; 8 | const pathConverter = require('./util/converter.path'); 9 | 10 | module.exports = { 11 | 12 | refresh(vorpal, cb) { 13 | cb = cb || function () {}; 14 | username().then(username => { 15 | const user = username; 16 | const host = String(os.hostname()).split('.')[0]; 17 | const home = pathConverter.unix(userHome); 18 | let cwd = pathConverter.unix(process.cwd()); 19 | cwd = cwd.replace(home, '~'); 20 | let delimiter = `${user}@${host}:${cwd}$`; 21 | // If we're on linux-based systems, color 22 | // the prompt so we don't get confused. 23 | if (!isWindows) { 24 | delimiter = `\u001b[32m${delimiter}\u001b[39m`; 25 | } 26 | vorpal.delimiter(delimiter); 27 | cb(null); 28 | }).catch(err => cb(err)); 29 | }, 30 | 31 | getHomeDir() { 32 | return userHome; 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /src/help/alias.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: alias [OPTION] [name[=value] ...] 3 | Define or display aliases. 4 | 5 | Without arguments, \`alias' prints the list of aliases in the reusable 6 | form \`alias NAME=VALUE' on standard output. 7 | 8 | Otherwise, an alias is defined for each NAME whose VALUE is given. 9 | A trailing space in VALUE causes the next word to be checked for 10 | alias substitution when the alias is expanded. 11 | 12 | -p print all defined aliases in a reusable format 13 | --help display this help and exit 14 | 15 | Report alias bugs to 16 | Cash home page: 17 | `; 18 | -------------------------------------------------------------------------------- /src/help/cat.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: cat [OPTION]... [FILE]... 3 | Concatenate FILE(s), or standard input, to standard output. 4 | 5 | -A, --show-all equivalent to -vET 6 | -b, --number-nonblank number nonempty output lines, overrides -n 7 | -e equivalent to -vE 8 | -E, --show-ends display $ at end of each line 9 | -n, --number number all output lines 10 | -s, --squeeze-blank suppress repeated empty output lines 11 | -t equivalent to -vT 12 | -T, --show-tabs display TAB characters as ^I 13 | -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB 14 | --help display this help and exit 15 | 16 | With no FILE, or when FILE is -, read standard input. 17 | 18 | Examples: 19 | cat f - g Output f's contents, then standard input, then g's contents. 20 | cat Copy standard input to standard output. 21 | 22 | Report cat bugs to 23 | Cash home page: 24 | `; 25 | -------------------------------------------------------------------------------- /src/help/cd.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: cd [DIR]... 3 | Change the cash working directory. 4 | 5 | Change the current directory to DIR. The default DIR is the value of the 6 | HOME shell variable. 7 | 8 | Report cd bugs to 9 | Cash home page: 10 | `; 11 | -------------------------------------------------------------------------------- /src/help/clear.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: clear 3 | Clear the terminal screen 4 | 5 | --help display this help and exit 6 | 7 | Clear ignores any command-line parameters that may be present. 8 | 9 | Report clear bugs to 10 | Cash home page: 11 | `; 12 | -------------------------------------------------------------------------------- /src/help/cp.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: cp [OPTION]... [-T] SOURCE DEST 3 | or: cp [OPTION]... SOURCE... DIRECTORY 4 | Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. 5 | 6 | -f, --force if an existing destination file cannot be 7 | opened, remove it and try again (this option 8 | is ignored when the -n option is also used) 9 | -n, --no-clobber do not overwrite an existing file (overrides 10 | a previous -i option) 11 | -R, -r, --recursive copy directories recursively 12 | --help display this help and exit 13 | 14 | Report cp bugs to 15 | Cash home page: 16 | `; 17 | -------------------------------------------------------------------------------- /src/help/echo.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: echo [OPTION]... [ARG ...] 3 | Write arguments to the standard output. 4 | 5 | Display the ARGs, separated by a single space character and followed by a 6 | newline, on the standard output. 7 | 8 | -e enable interpretation of the following backslash escapes 9 | -e explicitly suppress interpretation of backslash escapes 10 | --help display this help and exit 11 | 12 | \`echo' interprets the following backslash-escaped characters: 13 | \b backspace 14 | \c suppress further output 15 | \n new line 16 | \r carriage return 17 | \t horizontal tab 18 | \\ backslash 19 | 20 | Report echo bugs to 21 | Cash home page: 22 | `; 23 | -------------------------------------------------------------------------------- /src/help/export.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: export [OPTION] [name[=value]] 3 | Export variables into the environment 4 | 5 | Without arguments, \`export' prints the list of environnmental variables in the 6 | form \`declare -x NAME="VALUE"' on standard output. This is the same as the 7 | behavior if \`-p' is given. 8 | 9 | Otherwise, the variable is exported to the environment. If the variable has 10 | already been defined in the environment (ex. \`PATH'), then this will either 11 | redefine its value or do nothing (if no value is passed in). If the variable is 12 | not already in the environment, it will be added with the \`VALUE' given 13 | (defaults to the empty string). 14 | 15 | -p print all exported variables in a reusable format 16 | --help display this help and exit 17 | 18 | Report export bugs to 19 | Cash home page: 20 | `; 21 | -------------------------------------------------------------------------------- /src/help/false.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: false [OPTION] 3 | Do nothing, unsuccessfully 4 | 5 | This command simply exits with status 1 (failure). 6 | 7 | --help display this help and exit 8 | 9 | Report false bugs to 10 | Cash home page: 11 | `; 12 | -------------------------------------------------------------------------------- /src/help/grep.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: grep [OPTION]... PATTERN [FILE]... 3 | Search for PATTERN in each FILE or standard input. 4 | PATTERN is, by default, a basic regular expression (BRE). 5 | Example: grep -i 'hello world' menu.h main.c 6 | 7 | iwsvmbnHhqr 8 | 9 | Regexp selection and interpretation: 10 | -i, --ignore-case ignore case distinctions 11 | -w, --word-regexp force PATTERN to match only whole words 12 | 13 | Miscellaneous: 14 | -s, --no-messages suppress error messages 15 | -v, --invert-match select non-matching lines 16 | --help display this help and exit 17 | 18 | Output control: 19 | -n, --line-number print line number with output lines 20 | -H, --with-filename print the file name for each match 21 | -h, --no-filename suppress the file name prefix on output 22 | -q, --quiet, --silent suppress all normal output 23 | -r, --recursive like --directories=recurse 24 | --include search only files that match FILE_PATTERN 25 | 26 | When FILE is -, read standard input. With no FILE, read . if a command-line 27 | -r is given, - otherwise. If fewer than two FILEs are given, assume -h. 28 | Exit status is 0 if any line is selected, 1 otherwise; 29 | if any error occurs and -q is not given, the exit status is 2. 30 | 31 | Report grep bugs to 32 | Cash home page: 33 | `; 34 | -------------------------------------------------------------------------------- /src/help/head.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: head [OPTION]... [FILE]... 3 | Print the first 10 lines of each FILE to standard output. 4 | With more than one FILE, precede each with a header giving the file name. 5 | With no FILE, or when FILE is -, read standard input. 6 | 7 | -n, --lines output the last N lines, instead of the last 10 8 | -q, --silent suppresses printing of headers when multiple files 9 | are being examined 10 | -v, --verbose always output headers giving file names 11 | --help display this help and exit 12 | 13 | Report head bugs to 14 | Cash home page: 15 | `; 16 | -------------------------------------------------------------------------------- /src/help/kill.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: kill [OPTION] pid | jobspec ... or kill -l [sigspec] 3 | Send a signal to a job. 4 | 5 | Send the processes identified by PID or JOBSPEC the signal named by 6 | SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then 7 | SIGTERM is assumed. 8 | 9 | -s sig SIG is a signal name 10 | -n sig SIG is a signal number 11 | -l [sigspec] list the signal names; if arguments follow \`-l' they 12 | are assumed to be signal numbers for which names 13 | should be listed 14 | --help display this help and exit 15 | 16 | Exit status: 17 | 0 if OK, 18 | 1 if an invalid option is given or an error occurs. 19 | 20 | Report kill bugs to 21 | Cash home page: 22 | `; 23 | -------------------------------------------------------------------------------- /src/help/mkdir.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: mkdir [OPTION]... DIRECTORY... 3 | Create the DIRECTORY(ies), if they do not already exist. 4 | 5 | -p, --parents no error if existing, make parent directories as needed 6 | -v, --verbose print a message for each created directory 7 | --help display this help and exit 8 | 9 | Report mkdir bugs to 10 | Cash home page: 11 | `; 12 | -------------------------------------------------------------------------------- /src/help/mv.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: mv [OPTION]... [-T] SOURCE DEST 3 | or: mv [OPTION]... SOURCE... DIRECTORY 4 | or: mv [OPTION]... -t DIRECTORY SOURCE... 5 | Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. 6 | 7 | -f, --force do not prompt before overwriting 8 | -n, --no-clobber do not overwrite an existing file 9 | --striptrailingslashes remove any trailing slashes from each SOURCE 10 | argument 11 | -v, --verbose explain what is being done 12 | --help display this help and exit 13 | 14 | If you specify -f and -n, only -f takes effect. 15 | 16 | Report mv bugs to 17 | Cash home page: 18 | `; 19 | -------------------------------------------------------------------------------- /src/help/pwd.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: pwd [-LP] 3 | Print the name of the current working directory. 4 | 5 | --help display this help and exit 6 | 7 | Exit status: 8 | 0 if OK, 9 | 1 if an invalid option is given or the current directory 10 | cannot be read. 11 | 12 | Report pwd bugs to 13 | Cash home page: 14 | `; 15 | -------------------------------------------------------------------------------- /src/help/rm.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: rm [OPTION]... FILE... 3 | Remove (unlink) the FILE(s). 4 | 5 | -f, --force ignore nonexistent files and arguments, never prompt 6 | -r, -R, --recursive remove directories and their contents recursively 7 | --help display this help and exit 8 | 9 | By default, rm does not remove directories. Use the --recursive (-r or -R) 10 | option to remove each listed directory, too, along with all of its contents. 11 | 12 | To remove a file whose name starts with a '-', for example '-foo', 13 | use one of these commands: 14 | rm -- -foo 15 | rm ./-foo 16 | 17 | Note that if you use rm to remove a file, it might be possible to recover 18 | some of its contents, given sufficient expertise and/or time. 19 | 20 | Report rm bugs to 21 | Cash home page: 22 | `; 23 | -------------------------------------------------------------------------------- /src/help/sort.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: sort [OPTION]... [FILE]... 3 | Write sorted concatenation of all FILE(s) to standard output. 4 | 5 | Ordering options: 6 | -M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC' 7 | -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G) 8 | -n, --numeric-sort compare according to string numerical value 9 | -R, --random-sort sort by random hash of keys 10 | -r, --reverse reverse the result of comparisons 11 | 12 | Other options: 13 | -c, --check, 14 | --check=diagnose-first check for sorted input; do not sort 15 | -o, --output=FILE write result to FILE instead of standard output 16 | --help display this help and exit 17 | 18 | With no FILE, or when FILE is -, read standard input. 19 | 20 | Report sort bugs to 21 | Cash home page: 22 | `; 23 | -------------------------------------------------------------------------------- /src/help/source.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: source FILENAME [ARGUMENTS...] 3 | or: . FILENAME [ARGUMENTS...] 4 | Read and execute commands from the filename argument in the current shell. 5 | 6 | When a script is run using source, it runs within the existing shell and any 7 | change of directory or modified variables or aliases will persist after the 8 | script completes. Scripts may contain any commands that cash supports. 9 | 10 | --help display this help and exit 11 | 12 | Report source bugs to 13 | Cash home page: 14 | `; 15 | -------------------------------------------------------------------------------- /src/help/tail.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: tail [OPTION]... [FILE]... 3 | Display the last part of a file. 4 | 5 | Print the last 10 lines of each FILE to standard output. With more 6 | than one FILE, precede each with a header giving the file name. 7 | 8 | -n, --lines output the last N lines, instead of the last 10 9 | -q, --silent suppresses printing of headers when multiple files 10 | are being examined 11 | -v, --verbose always output headers giving file names 12 | --help display this help and exit 13 | 14 | Report tail bugs to 15 | Cash home page: 16 | `; 17 | -------------------------------------------------------------------------------- /src/help/touch.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: touch [OPTION]... FILE... 3 | Update the access and modification times of each FILE to the current time. 4 | 5 | A FILE argument that does not exist is created empty, unless -c is 6 | supplied. 7 | 8 | -a change only the access time 9 | -c, --no-create do not create any files 10 | -d, --date parse STRING and use it instead of current time 11 | -m change only the modification time 12 | -r, --reference use this file's times instead of current time 13 | --time change the specified time: 14 | WORD is access, atime, or use: equivalent to -a 15 | WORD is modify or mtime: equivalent to -m 16 | --help display this help and exit 17 | 18 | Report touch bugs to 19 | Cash home page: 20 | `; 21 | -------------------------------------------------------------------------------- /src/help/true.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: true [OPTION] 3 | Do nothing, successfully 4 | 5 | This command simply exits with status 0 (success). 6 | 7 | --help display this help and exit 8 | 9 | Report true bugs to 10 | Cash home page: 11 | `; 12 | -------------------------------------------------------------------------------- /src/help/unalias.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: unalias [OPTION] name ... 3 | Remove each name from the list of defined aliases. 4 | 5 | -a remove all alias definitions 6 | --help display this help and exit 7 | 8 | Exit status: 9 | 0 if OK, 10 | 1 if a name is not an existing alias. 11 | 12 | Report unalias bugs to 13 | Cash home page: 14 | `; 15 | -------------------------------------------------------------------------------- /src/help/which.js: -------------------------------------------------------------------------------- 1 | module.exports = ` 2 | Usage: which COMMAND 3 | Look for COMMAND in $PATH. 4 | 5 | --help display this help and exit 6 | 7 | Report which bugs to 8 | Cash home page: 9 | `; 10 | -------------------------------------------------------------------------------- /src/preparser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Replace out env variables. 4 | const parseEnvVariables = function (input) { 5 | const referenceRegex = 6 | /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g; 7 | 8 | return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) { 9 | const varName = capture1 || capture2 || capture3; 10 | // Return the value of the variable, or the empty string if not there 11 | return process.env.hasOwnProperty(varName) ? process.env[varName] : ''; 12 | }); 13 | }; 14 | 15 | const preparser = function (input) { 16 | input = parseEnvVariables(input); 17 | return input; 18 | }; 19 | 20 | module.exports = preparser; 21 | -------------------------------------------------------------------------------- /src/util/colorFile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const strip = require('./stripAnsi'); 4 | 5 | const chalk = {}; 6 | const map = {cyan: 36, red: 31, magenta: 35}; 7 | Object.keys(map).forEach(function (key, value) { 8 | chalk[key] = function (str) { 9 | return `\u001b[${value}m${str}\u001b[39m`; 10 | }; 11 | }); 12 | 13 | /** 14 | * Wraps file strings in ANSI colors 15 | * based on their extension. 16 | * 17 | * @param {file} str 18 | * @return {String} 19 | * @api public 20 | */ 21 | 22 | module.exports = function (file) { 23 | const audio = ['aac', 'au', 'flac', 'mid', 'midi', 'mka', 'mp3', 'mpc', 'ogg', 'ra', 'wav', 'axa', 'oga', 'spx', 'xspf']; 24 | const archive = ['tar', 'tgz', 'arj', 'taz', 'lzh', 'lzma', 'tlz', 'txz', 'zip', 'z', 'Z', 'dz', 'gz', 'lz', 'xz', 'bz2', 'bz', 'tbz', 'tbz2', 'tz', 'deb', 'rpm', 'jar', 'rar', 'ace', 'zoo', 'cpio', '7z', 'rz']; 25 | const images = ['jpg', 'jpeg', 'gif', 'bmp', 'pbm', 'pgm', 'ppm', 'tga', 'xbm', 'xpm', 'tif', 'tiff', 'png', 'svg', 'svgz', 'mng', 'pcx', 'mov', 'mpg', 'mpeg', 'm2v', 'mkv', 'ogm', 'mp4', 'm4v', 'mp4v', 'vob', 'qt', 'nuv', 'wmv', 'asf', 'rm', 'rmvb', 'flc', 'avi', 'fli', 'flv', 'gl', 'dl', 'xcf', 'xwd', 'yuv', 'cgm', 'emf', 'axv', 'anx', 'ogv', 'ogx']; 26 | 27 | let extension = String(file).toLowerCase().trim().split('.'); 28 | extension = extension[extension.length - 1]; 29 | 30 | let colored = strip(file); 31 | colored = (audio.indexOf(extension) > -1) ? chalk.cyan(file) : 32 | (archive.indexOf(extension) > -1) ? chalk.red(file) : 33 | (images.indexOf(extension) > -1) ? chalk.magenta(file) : 34 | colored; 35 | 36 | return colored; 37 | }; 38 | -------------------------------------------------------------------------------- /src/util/columnify.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const strip = require('./stripAnsi'); 4 | const pad = require('./pad'); 5 | 6 | /** 7 | * Formats an array to display in a TTY 8 | * in a pretty fashion. 9 | * 10 | * @param {Array} arr 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (arr, options) { 16 | arr = arr || []; 17 | options = options || {}; 18 | const bk = JSON.parse(JSON.stringify(arr)); 19 | const width = (options.width && !isNaN(options.width)) ? 20 | options.width : 21 | process.stdout.columns; 22 | const longest = strip(bk.sort(function (a, b) { 23 | return strip(b).length - strip(a).length; 24 | })[0] || '').length + 2; 25 | const fullWidth = strip(arr.join('')).length; 26 | const fitsOneLine = ((fullWidth + (arr.length * 2)) <= width); 27 | let cols = Math.floor(width / longest); 28 | cols = (cols < 1) ? 1 : cols; 29 | if (fitsOneLine) { 30 | return arr.join(' '); 31 | } 32 | let col = 0; 33 | const lines = []; 34 | let line = ''; 35 | for (let i = 0; i < arr.length; ++i) { 36 | if (col < cols) { 37 | col++; 38 | } else { 39 | if (String(strip(line)).trim() !== '') { 40 | lines.push(line); 41 | } 42 | line = ''; 43 | col = 1; 44 | } 45 | if (cols === 1) { 46 | // If we have files so damn 47 | // long that we wrap, don't pad 48 | // the lines. 49 | line += arr[i]; 50 | } else { 51 | // Pad the lines based on the 52 | // longest word. 53 | /* istanbul ignore next */ 54 | line += pad(arr[i], longest, ' '); 55 | } 56 | } 57 | if (line !== '') { 58 | lines.push(line); 59 | } 60 | return lines.join('\n'); 61 | }; 62 | -------------------------------------------------------------------------------- /src/util/converter.date.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Date conversion utilities 5 | */ 6 | 7 | const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 8 | 9 | function pad(num, padding) { 10 | padding = padding || '0'; 11 | num = parseFloat(num); 12 | if (num < 10) { 13 | return `${padding}${num}`; 14 | } 15 | return num; 16 | } 17 | 18 | module.exports = { 19 | 20 | unix(dt) { 21 | let date = dt; 22 | let day = pad(date.getDate(), ' '); 23 | const month = months[date.getMonth()]; 24 | const hour = pad(date.getHours()); 25 | const min = pad(date.getMinutes()); 26 | const hourMin = `${hour}:${min}`; 27 | day = (day.length === 1) ? (` ${day}`) : day; 28 | date = `${month} ${day} ${hourMin}`; 29 | return date; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /src/util/converter.path.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | /** 6 | * Path conversion utilities 7 | */ 8 | 9 | module.exports = { 10 | 11 | unix(str) { 12 | let input = path.normalize(str); 13 | input = input.replace(/\\/g, '\/'); 14 | const parts = input.split(':'); 15 | const drive = parts.shift(); 16 | const isLetter = (drive.length === 1 && drive.match(/[a-z]/i)); 17 | const result = (isLetter) ? drive + parts.join(':') : input; 18 | return result; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /src/util/converter.permissions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Permission conversion utilities 5 | */ 6 | 7 | module.exports = { 8 | 9 | listing: { 10 | 0: '---', 11 | 1: '--x', 12 | 2: '-w-', 13 | 3: '-wx', 14 | 4: 'r--', 15 | 5: 'r-x', 16 | 6: 'rw-', 17 | 7: 'rwx' 18 | }, 19 | 20 | modeToRWX(mode) { 21 | const octal = this.modeToOctal(mode); 22 | const rwx = this.octalToRWX(octal); 23 | return rwx; 24 | }, 25 | 26 | modeToOctal(mode) { 27 | const octal = `0${(mode & 0o777).toString(8)}`; 28 | return octal; 29 | }, 30 | 31 | octalToRWX(octal) { 32 | if (!octal) { 33 | return undefined; 34 | } 35 | const list = this.listing; 36 | const a = list[String(octal).charAt(1)]; 37 | const b = list[String(octal).charAt(2)]; 38 | const c = list[String(octal).charAt(3)]; 39 | return a + b + c; 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /src/util/expand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const glob = require('glob'); 4 | 5 | /** 6 | * Expands wildcard files, etc. out 7 | * into their full paths. 8 | * 9 | * @param {Array} list 10 | * @return {Array} 11 | * @api public 12 | */ 13 | 14 | module.exports = function (list) { 15 | const total = list.length; 16 | const files = []; 17 | if (list.length < 1) { 18 | return []; 19 | } 20 | for (let i = 0; i < total; ++i) { 21 | const res = glob.sync(list[i], {}); 22 | files[i] = (res.length > 0) ? 23 | res : 24 | list[i]; 25 | } 26 | let out = []; 27 | for (let i = 0; i < files.length; ++i) { 28 | out = (Array.isArray(files[i])) ? 29 | out.concat(files[i]) : 30 | out.concat([files[i]]); 31 | } 32 | return out; 33 | }; 34 | -------------------------------------------------------------------------------- /src/util/fetch.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | 6 | const expand = require('./expand'); 7 | 8 | /** 9 | * Reads the contents of an array of 10 | * files and returns the array. 11 | * 12 | * @param {Array} files 13 | * @param {String} stdin 14 | * @param {Object} options 15 | * @return {Array} 16 | * @api public 17 | */ 18 | 19 | module.exports = function (files, stdin, options) { 20 | files = files || []; 21 | stdin = (stdin !== undefined) ? stdin : []; 22 | const f = expand(files); 23 | 24 | if (!(f.length === 0 && files.length > 0)) { 25 | files = f; 26 | } 27 | 28 | for (let i = 0; i < files.length; ++i) { 29 | try { 30 | const stat = fs.statSync(files[i]); 31 | if (stat.isDirectory()) { 32 | files[i] = options.onDirectory(files[i]); 33 | } else { 34 | files[i] = String(fs.readFileSync(path.normalize(files[i]), 'utf8')); 35 | } 36 | } catch (e) { 37 | files[i] = options.onInvalidFile(files[i]); 38 | } 39 | } 40 | 41 | const agg = (files.length < 1) ? stdin : files; 42 | const final = []; 43 | 44 | for (let i = 0; i < agg.length; ++i) { 45 | if (agg[i] !== undefined) { 46 | final.push(agg[i]); 47 | } 48 | } 49 | return final; 50 | }; 51 | -------------------------------------------------------------------------------- /src/util/fileFromPath.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Parses a path and returns just the file 5 | * 6 | * @param {path} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (path) { 12 | let fileShort = String(path).split('/'); 13 | fileShort = fileShort[fileShort.length - 1]; 14 | fileShort = fileShort.split('\\'); 15 | fileShort = fileShort[fileShort.length - 1]; 16 | return fileShort; 17 | }; 18 | -------------------------------------------------------------------------------- /src/util/intercept.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Intercepts stdout, passes thru callback 5 | * also pass console.error thru stdout so it goes to callback too 6 | * (stdout.write and stderr.write are both refs to the same stream.write function) 7 | * returns an unhook() function, call when done intercepting 8 | * 9 | * @param {Function} callback 10 | * @return {Function} 11 | */ 12 | 13 | module.exports = function (callback) { 14 | const oldStdoutWrite = process.stdout.write; 15 | const oldConsoleError = console.error; 16 | process.stdout.write = (function (write) { 17 | return function (string) { 18 | const args = Array.from(arguments); 19 | args[0] = interceptor(string); 20 | write.apply(process.stdout, args); 21 | }; 22 | }(process.stdout.write)); 23 | 24 | console.error = (function () { 25 | return function () { 26 | const args = Array.from(arguments); 27 | args.unshift('\x1b[31m[ERROR]\x1b[0m'); 28 | console.log.apply(console.log, args); 29 | }; 30 | }(console.error)); 31 | 32 | function interceptor(string) { 33 | // only intercept the string 34 | const result = callback(string); 35 | if (typeof result === 'string') { 36 | string = result.replace(/\n$/, '') + (result && (/\n$/).test(string) ? '\n' : ''); 37 | } 38 | return string; 39 | } 40 | // puts back to original 41 | return function unhook() { 42 | process.stdout.write = oldStdoutWrite; 43 | console.error = oldConsoleError; 44 | }; 45 | }; 46 | -------------------------------------------------------------------------------- /src/util/interfacer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Simple binding interface between 5 | * each command's function and the caller 6 | * of the command, whether by `cash.command` 7 | * or by being invoked by Vorpal. 8 | * This exists to abstract complexity 9 | * and create a standard in interfacing 10 | * commands acorss muliple execution paths. 11 | * 12 | * @param {Object} opt 13 | * @api public 14 | */ 15 | 16 | module.exports = function (opt) { 17 | const self = this; 18 | let stdout = ''; 19 | opt.options = opt.options || {}; 20 | opt.callback = opt.callback || function () {}; 21 | opt.command = opt.command || {exec() {}}; 22 | 23 | const logger = { 24 | log(out) { 25 | stdout += `${out}\n`; 26 | if (opt.silent !== true) { 27 | // process.stdout.write(out) // to do - handle newline problem. 28 | self.log(out); 29 | } 30 | } 31 | }; 32 | 33 | function onResult(result) { 34 | result = (result === undefined) ? 0 : result; 35 | opt.callback(null, stdout); 36 | return stdout; 37 | } 38 | 39 | if (opt.async === true) { 40 | return opt.command.exec.call(logger, opt.args, opt.options, onResult); 41 | } 42 | return onResult(opt.command.exec.call(logger, opt.args, opt.options)); 43 | }; 44 | -------------------------------------------------------------------------------- /src/util/lpad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads to the left hand. 7 | * 8 | * @param {String} str 9 | * @param {Integer} width 10 | * @param {String} delimiter 11 | * @return {String} 12 | * @api public 13 | */ 14 | 15 | module.exports = function (str, width, delimiter) { 16 | width = Math.floor(width); 17 | delimiter = delimiter || ' '; 18 | const len = Math.max(0, width - strip(str).length); 19 | return Array(len + 1).join(delimiter) + str; 20 | }; 21 | -------------------------------------------------------------------------------- /src/util/pad.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const strip = require('./stripAnsi'); 4 | 5 | /** 6 | * Pads a value with with space or 7 | * a specified delimiter to match a 8 | * given width. 9 | * 10 | * @param {String} str 11 | * @param {Integer} width 12 | * @param {String} delimiter 13 | * @return {String} 14 | * @api public 15 | */ 16 | 17 | module.exports = function (str, width, delimiter) { 18 | width = Math.floor(width); 19 | delimiter = delimiter || ' '; 20 | const len = Math.max(0, width - strip(str).length); 21 | return str + Array(len + 1).join(delimiter); 22 | }; 23 | -------------------------------------------------------------------------------- /src/util/stripAnsi.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Removes all ansi characters. 5 | * 6 | * @param {String} str 7 | * @return {String} 8 | * @api public 9 | */ 10 | 11 | module.exports = function (str) { 12 | const ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; 13 | return typeof str === 'string' ? str.replace(ansiRegex, '') : str; 14 | }; 15 | -------------------------------------------------------------------------------- /src/util/unlinkSync.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | 5 | /** 6 | * Normalizes _unlinkSync() across 7 | * platforms to match Unix behavior, i.e. 8 | * file can be unlinked even its it's 9 | * read only. 10 | * See https://github.com/joyent/node/issues/3006 11 | * 12 | * @param {String} file 13 | * @api public 14 | */ 15 | 16 | module.exports = function (file) { 17 | try { 18 | fs.unlinkSync(file); 19 | } catch (e) { 20 | // Try to override file permission 21 | /* istanbul ignore if */ 22 | if (e.code === 'EPERM') { 23 | fs.chmodSync(file, '0666'); 24 | fs.unlinkSync(file); 25 | } else { 26 | /* istanbul ignore next */ 27 | throw e; 28 | } 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /src/util/walkDir.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | 6 | /** 7 | * Walks a single directory calling 8 | * a callback function for each file or 9 | * folder, returning the path and results 10 | * of fs.statSync. 11 | * 12 | * @param {String} currentDirPath 13 | * @param {Function} callback 14 | * @param {Function} errorCallback 15 | * @api public 16 | */ 17 | module.exports = function (currentDirPath, callback, errorCallback) { 18 | /** 19 | * @param {String} path 20 | * @param {Function} cbk 21 | * @param {Function} ecbk 22 | */ 23 | function readFile(path, cbk, ecbk) { 24 | try { 25 | const stat = fs.statSync(path); 26 | if (stat.isFile() || stat.isDirectory()) { 27 | cbk(path, stat); 28 | } 29 | } catch (e) { 30 | ecbk(path, e); 31 | } 32 | } 33 | 34 | try { 35 | const dirs = fs.readdirSync(currentDirPath); 36 | dirs.forEach(function (name) { 37 | const filePath = path.join(currentDirPath, name); 38 | readFile(filePath, callback, errorCallback); 39 | }); 40 | } catch (e) { 41 | if (e.code === 'ENOTDIR') { 42 | readFile(currentDirPath, callback, errorCallback); 43 | } else { 44 | errorCallback(currentDirPath, e); 45 | } 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /src/util/walkDirRecursive.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | 6 | /** 7 | * Recursively walks through and executes 8 | * a callback function for each directory found. 9 | * 10 | * @param {String} currentDirPath 11 | * @param {Function} callback 12 | * @api public 13 | */ 14 | 15 | module.exports = function (currentDirPath, callback) { 16 | fs.readdirSync(currentDirPath).forEach(function (name) { 17 | const filePath = path.join(currentDirPath, name); 18 | const stat = fs.statSync(filePath); 19 | if (stat.isDirectory()) { 20 | callback(filePath, stat); 21 | module.exports(filePath, callback); 22 | } 23 | }); 24 | }; 25 | -------------------------------------------------------------------------------- /test/clear.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | 7 | describe('clear', function () { 8 | it('should exist and be a function', function () { 9 | should.exist(cash.clear); 10 | }); 11 | 12 | it('should run without throwing', function () { 13 | (function () { 14 | cash.clear(); 15 | }).should.not.throw(); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /test/help.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | const os = require('os'); 7 | 8 | describe('help', function () { 9 | it('should exist', function () { 10 | should.exist(cash); 11 | }); 12 | 13 | // Appveyor creates some problems 14 | // that I can't reproduce on any Windows 15 | // box. Need to work on this. 16 | if (os.platform() !== 'win32') { 17 | it('should show help when passed an invalid command', function () { 18 | const out = cash('banjo kazooie!'); 19 | out.should.containEql('Cash'); 20 | out.should.containEql('These shell commands are defined internally'); 21 | }); 22 | } 23 | }); 24 | -------------------------------------------------------------------------------- /test/pwd.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | const $ = require('shelljs'); 7 | 8 | describe('pwd', function () { 9 | it('should exist and be a function', function () { 10 | should.exist(cash.pwd); 11 | }); 12 | 13 | it('should print the current working directory', function () { 14 | cash.pwd().should.containEql('cash'); 15 | }); 16 | 17 | it('should change on directory change', function () { 18 | String(cash.pwd()).should.not.containEql('node_modules'); 19 | $.cd('./node_modules'); 20 | String(cash.pwd()).should.containEql('node_modules'); 21 | $.cd('..'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/true.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | 7 | describe('true', function () { 8 | it('should exist and be a function', function () { 9 | should.exist(cash.true); 10 | }); 11 | 12 | it('should do nothing when called', function () { 13 | const results = cash.true(); 14 | console.log(typeof results); 15 | results.should.equal(''); 16 | }); 17 | 18 | describe('programmatic use', function () { 19 | it('should execute in vorpal mode sync', function () { 20 | const result = cash('true'); 21 | result.should.equal(''); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/util/playground.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const cash = require('../../dist/index.js'); 4 | 5 | 6 | let result = cash('fooo!!!!!'); 7 | 8 | console.log('!!!!!!!!!' + result); 9 | console.log('----------------'); -------------------------------------------------------------------------------- /test/util/util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const $ = require('shelljs'); 4 | const fs = require('fs-extra'); 5 | 6 | module.exports = { 7 | 8 | writeSampleDir(cb) { 9 | // If tests fail mid, script cleanup doesn't happen. 10 | // This makes sure we are in the right dir before 11 | // trying to write. 12 | if (String(process.cwd()).indexOf('/cash') === -1) { 13 | process.chdir(`${__dirname}/../..`); 14 | } 15 | 16 | fs.removeSync('./testing'); 17 | 18 | $.mkdir('-p', './testing/'); 19 | $.mkdir('-p', './testing/sub/'); 20 | 21 | let filler = 'fill|'; 22 | 23 | function writeDir(dir, cbk) { 24 | const files = ['a.txt', 'c.exe', 'd.json', 'e.gif', 'b.tgz', 'f.jpg', 'g', '.hidden']; 25 | function write() { 26 | const next = files.shift(); 27 | if (next) { 28 | filler = double(filler); 29 | new $.ShellString(filler).to(dir + next); 30 | setTimeout(function () { 31 | write(); 32 | }, 10); 33 | } else { 34 | cbk(); 35 | } 36 | } 37 | write(); 38 | } 39 | 40 | writeDir('./testing/', function () { 41 | writeDir('./testing/sub/', function () { 42 | cb(); 43 | }); 44 | }); 45 | }, 46 | 47 | deleteSampleDir() { 48 | fs.removeSync('./testing'); 49 | } 50 | }; 51 | 52 | function double(str) { 53 | return str + str + str.slice(0, 100); 54 | } 55 | -------------------------------------------------------------------------------- /test/vorpal.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | const commands = require('../commands.json'); 7 | 8 | describe('vorpal', function () { 9 | it('should exist', function () { 10 | should.exist(cash); 11 | }); 12 | 13 | it('should execute all commands without erroring', function () { 14 | (function () { 15 | const cmds = commands.commands; 16 | for (let i = 0; i < cmds.length; ++i) { 17 | cash(`${cmds[i]}`); 18 | } 19 | }).should.not.throw(); 20 | }); 21 | 22 | it('should require commands without vorpal', function () { 23 | (function () { 24 | const cmds = commands.commands; 25 | for (let i = 0; i < cmds.length; ++i) { 26 | require(`../dist/commands/${cmds[i]}.js`)(); 27 | } 28 | }).should.not.throw(); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /test/which.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | const should = require('should'); 5 | const cash = require('../dist/index.js'); 6 | 7 | describe('true', function () { 8 | it('should exist and be a function', function () { 9 | should.exist(cash.which); 10 | }); 11 | 12 | it('should do nothing when called', function () { 13 | const results = cash.which(); 14 | console.log(typeof results); 15 | results.should.equal(''); 16 | }); 17 | 18 | it('should find cmd when called', function () { 19 | const results = cash.which('cmd'); 20 | console.log(typeof results); 21 | results.should.not.equal(''); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/windows.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('assert'); 4 | require('should'); 5 | const cash = require('../dist/index.js'); 6 | 7 | describe('windows', function () { 8 | it('execute a catch command', function () { 9 | cash('cash-test'); 10 | }); 11 | }); 12 | --------------------------------------------------------------------------------