├── .gitignore ├── package.json ├── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "explain-command", 3 | "version": "1.0.4", 4 | "description": "Explain shell commands in the shell", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/jacksonp/explain-command.git" 8 | }, 9 | "bin": { 10 | "explain": "index.js" 11 | }, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "keywords": [ 16 | "man page", 17 | "command", 18 | "options", 19 | "explain", 20 | "manual" 21 | ], 22 | "author": "Jackson Pauls (https://www.mankier.com/)", 23 | "license": "ISC" 24 | } 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | var 3 | https = require('https'), 4 | os = require('os'); 5 | 6 | 7 | function exit() { 8 | process.stdout.write('Bye!' + os.EOL); 9 | process.exit(); 10 | } 11 | 12 | process.stdin.resume(); 13 | process.on('SIGINT', exit); 14 | 15 | 16 | function explain(cmd, callback) { 17 | https.get('https://www.mankier.com/api/v2/explain/?cols=' + process.stdout.columns + '&q=' + encodeURIComponent(cmd), function (res) { 18 | res.on('data', function (d) { 19 | process.stdout.write(d); 20 | }); 21 | res.on('end', function () { 22 | callback(); 23 | }); 24 | }).on('error', function (e) { 25 | console.log('Got error: ' + e.message); 26 | }); 27 | } 28 | 29 | if (process.argv.length === 2) { 30 | 31 | process.stdout.write('Command: '); 32 | 33 | process.stdin.resume(); 34 | process.stdin.setEncoding('utf8'); 35 | 36 | process.stdin.on('data', function (text) { 37 | var cmd = text.trim(); 38 | if (cmd === '' || cmd === 'quit') { 39 | exit(); 40 | } else { 41 | explain(cmd, function () { 42 | process.stdout.write('Command: '); 43 | }); 44 | } 45 | }); 46 | 47 | } else { 48 | 49 | var myArgs = process.argv.slice(2); 50 | explain(myArgs.join(' '), function () { 51 | process.exit(); 52 | }); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Install 2 | 3 | `$ sudo npm install -g explain-command` 4 | 5 | ## Use 6 | 7 | Explain a command from your command line: 8 | 9 | ``` 10 | $ explain tar -xf file.tar.gz 11 | 12 | tar(1) 13 | GNU tar is an archiving program designed to store multiple files in a single 14 | file (an archive), and to manipulate such archives. The archive can be either 15 | a regular file or a device (e.g. a tape drive, hence the name of the program, 16 | which stands for tape archiver), which can be located either on the local or 17 | on a remote machine. 18 | 19 | -x (-x, --extract, --get) 20 | Extract files from an archive. Arguments are optional. When given, they 21 | specify names of the archive members to be extracted. 22 | 23 | -f file.tar.gz (-f, --file=ARCHIVE) 24 | Use archive file or device ARCHIVE . If this option is not given, tar will 25 | first examine the environment [... truncated ...] 26 | ``` 27 | 28 | Interactive mode: 29 | 30 | ``` 31 | $ explain 32 | Command: du -s * | sort -n | tail 33 | 34 | du(1) 35 | Summarize disk usage of the set of FILEs, recursively for directories. 36 | Mandatory arguments to long options are mandatory for short options too. 37 | 38 | -s (-s, --summarize) 39 | display only a total for each argument 40 | 41 | * 42 | 43 | -------------------------------------------------------------------------pipe-- 44 | 45 | sort(1) 46 | Write sorted concatenation of all FILE(s) to standard output. With no FILE, 47 | or when FILE is -, read standard input. Mandatory arguments to long options 48 | are mandatory for short options too. 49 | 50 | -n (-n, --numeric-sort) 51 | compare according to string numerical value 52 | 53 | -------------------------------------------------------------------------pipe-- 54 | 55 | tail(1) 56 | Print the last 10 lines of each FILE to standard output. With more than one 57 | FILE, precede each with a header giving the file name. With no FILE, or when 58 | FILE is -, read standard input. Mandatory arguments to long options are 59 | mandatory for short options too. 60 | 61 | Command: 62 | Bye! 63 | ``` 64 | 65 | 66 | ## License 67 | 68 | ISC 69 | --------------------------------------------------------------------------------