Skip to content
Browse files

`--copmletion` option support

Closes #57
  • Loading branch information...
1 parent 0fc29e6 commit abfdfb8fd89e628d32de30a5264495cf0672042a @floatdrop floatdrop committed Jan 4, 2014
Showing with 48 additions and 1 deletion.
  1. +3 −0 bin/gulp.js
  2. +12 −0 completion/README.md
  3. +1 −1 index.js
  4. +32 −0 lib/completion.js
View
3 bin/gulp.js
@@ -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);
View
12 completion/README.md
@@ -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`.
View
2 index.js
@@ -1,6 +1,6 @@
/*jshint node:true */
-"use strict";
+'use strict';
var util = require('util');
var Orchestrator = require('orchestrator');
View
32 lib/completion.js
@@ -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.
Something went wrong with that request. Please try again.