Skip to content

Commit

Permalink
feat(completion): Emit completion events along package.json results
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed May 1, 2016
1 parent ce794d4 commit 2ed8ef5
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions lib/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ class Complete extends EventEmitter {
var first = line.split(' ')[0];
if (first) first = first.trim();

if (!this.completePackage(env)) {
debug('No tabtab configuration in package.json, will emit events.');

// Keeps emitting event only if previous one is not being listened to.
// Emits in series: first, prev and name.
var event = (first || env.prev || name).trim();
this.send(event, env, this.recv.bind(this))
|| this.send(env.prev.trim(), env, this.recv.bind(this))
|| this.send(name.trim(), env, this.recv.bind(this));
}
this.completePackage(env);

// Keeps emitting event only if previous one is not being listened to.
// Emits in series: first, prev and name.
var event = (first || env.prev || name).trim();
this.send(event, env, this.recv.bind(this))
|| this.send(env.prev.trim(), env, this.recv.bind(this))
|| this.send(name.trim(), env, this.recv.bind(this));
}

completePackage(env, stop) {
Expand Down Expand Up @@ -150,16 +148,6 @@ class Complete extends EventEmitter {
if (err) return this.emit('error', err);
completions = Array.isArray(completions) ? completions : [completions];

// only return results that match last part of the line (cursor right next
// to last word, without space)
// completions = completions.filter((result) => {
// if (!env) return true;
//
// return result.indexOf(env.last) !== -1;
// }).map((l) => {
// return l + ' ';
// });

var shell = (process.env.SHELL || '').split('/').slice(-1)[0];

if (shell === 'bash' || shell === 'zsh') console.log(completions.join('\n'));
Expand Down

0 comments on commit 2ed8ef5

Please sign in to comment.