Skip to content

Commit

Permalink
--copmletion option support
Browse files Browse the repository at this point in the history
Closes gulpjs#57
  • Loading branch information
floatdrop committed Jan 3, 2014
1 parent 0fc29e6 commit abfdfb8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var tasks = argv._;
var cliPkg = require('../package.json');

var localBaseDir = process.cwd();
var completion = require('../lib/completion');

if (argv.completion) { return completion.print(argv.completion); }

loadRequires(argv.require, localBaseDir);

Expand Down
12 changes: 12 additions & 0 deletions completion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Completion for gulp
> Thanks to grunt team and Tyler Kellen
To enable tasks auto-completion in shell you should add `eval "$(gulp --completion=shell)"` in your `.shellrc` file.

## Bash

Add `eval "$(gulp --completion=bash)"` to `~/.bashrc`.

## Zsh

Add `eval "$(gulp --completion=zsh)"` to `~/.zshrc`.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*jshint node:true */

"use strict";
'use strict';

var util = require('util');
var Orchestrator = require('orchestrator');
Expand Down
32 changes: 32 additions & 0 deletions lib/completion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Borrowed from grunt-cli
* http://gruntjs.com/
*
* Copyright (c) 2012 Tyler Kellen, contributors
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt-init/blob/master/LICENSE-MIT
*/

'use strict';

var fs = require('fs');
var path = require('path');

exports.print = function(name) {
var code = 0;
var filepath = path.join(__dirname, '../completion', name);
var output;
try {
output = String(fs.readFileSync(filepath));
} catch (err) {
code = 5;
output = 'echo "Specified gulp shell auto-completion rules ';
if (name && name !== 'true') {
output += 'for \'' + name + '\' ';
}
output += 'not found."';
}

console.log(output);
process.exit(code);
};

0 comments on commit abfdfb8

Please sign in to comment.