Skip to content

Commit

Permalink
fix: ensure fileformat is unix and remove code related to bash-comple…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
mklabs committed Jul 17, 2018
1 parent 4875c90 commit 9b83d76
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Expand Up @@ -21,7 +21,7 @@ if (opts.help) {
console.log(commands.help());
process.exit(0);
} else if (allowed.indexOf(cmd) !== -1) {
// debug('Run command %s with options', cmd, opts);
debug('Run command %s with options', cmd, opts);
commands[cmd](opts);
} else {
console.log(commands.help());
Expand Down
5 changes: 1 addition & 4 deletions lib/commands/index.js
Expand Up @@ -32,10 +32,7 @@ module.exports = class Commands {
// Commands

// Public: Fow now, just output to the console
install(options) {
options = options || {};
const script = this.complete.script(this.name, this.name || 'tabtab');

install(options = this.options) {
let shell = process.env.SHELL;
if (shell) shell = shell.split((process.platform !== 'win32') ? '/' : '\\').slice(-1)[0];

Expand Down
12 changes: 4 additions & 8 deletions lib/complete.js
Expand Up @@ -49,8 +49,6 @@ module.exports = class Complete extends EventEmitter {
super();
this.options = options || this.defaults;
this.options.name = this.options.name || this.resolve('name');
this.options.cache = typeof this.options.cache !== 'undefined' ? this.options.cache : true;
this.options.ttl = this.options.ttl || (1000 * 60 * 5);

this._results = [];
this._completions = [];
Expand Down Expand Up @@ -91,7 +89,7 @@ module.exports = class Complete extends EventEmitter {
const event = env.line.trim();

// We know emit the whole line, instead of emitting several events at once
debug('Sendind events', event);
debug('Sending events', event);
debug('With env', env);
this.send(event, env, (err, results) => {
debug('send, received results', results);
Expand Down Expand Up @@ -142,10 +140,6 @@ module.exports = class Complete extends EventEmitter {
let first = env.line.split(' ')[0];
let results = config[first];
if (!results) return;

debug('TEST', env.line);
debug('TEST2', results);
debug('TEST first', first);
return this.recv(null, results, env);
}

Expand Down Expand Up @@ -203,10 +197,12 @@ module.exports = class Complete extends EventEmitter {
});

this._results = this._results.concat(completions);
debug('this_results in addCompletions', this._results);
debug('process.env.SHELL', shell);
}

completionItem(str) {
debug('completion item', str, typeof str);
debug('!!completion item', str, typeof str);

if (typeof str !== 'string') return str;
const shell = (process.env.SHELL || '').split('/').slice(-1)[0];
Expand Down
64 changes: 4 additions & 60 deletions lib/installer.js
Expand Up @@ -13,9 +13,6 @@ Try running with sudo instead:
`;

// Public: Manage installation / setup of completion scripts.
//
// pkg-config --variable=completionsdir bash-completion
// pkg-config --variable=compatdir bash-completion
module.exports = class Installer {
get home() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
Expand Down Expand Up @@ -55,7 +52,7 @@ module.exports = class Installer {

writeTo(data) {
var destination = data.destination;
debug('Installing completion script to %s directory', destination);
debug('Installing completion script to %s file or directory', destination);

var script = this.complete.script(this.options.name, this.options.completer || this.options.name, this.template);

Expand Down Expand Up @@ -99,8 +96,8 @@ module.exports = class Installer {
}

installCompletion(destination, out) {
var name = this.options.name;
var script = this.complete.script(name, this.options.completer || name, this.template);
const name = this.options.name;
var script = this.complete.script(name, this.options.completer || name, this.template).replace(/\r\n/g, '\n'); // replace windows style line end no matter what, can cause issue
var filename = path.join(__dirname, '../.completions', name + '.' + this.template);
if(process.platform === 'win32') { filename = filename.replace(/\\/g, '/'); } // win32: replace backslashes with forward slashes
debug('Writing actual completion script to %s', filename);
Expand Down Expand Up @@ -234,27 +231,7 @@ module.exports = class Installer {
short: 'bash'
}];

return this.completionsdir()
.then((dir) => {
debug(dir);
if (dir) {
entries.push({
name: 'Bash completionsdir ( ' + dir + ' )',
value: dir
});
}
return this.compatdir();
})
.then((dir) => {
if (dir) {
entries.push({
name: 'Bash compatdir ( ' + dir + ' )',
value: dir
});
}

return entries;
});
return new Promise((resolve, reject) => resolve(entries));
}

zsh() {
Expand All @@ -272,37 +249,4 @@ module.exports = class Installer {
}]);
});
}

// Bash

// Public: pkg-config wrapper
pkgconfig(variable) {
return new Promise((r, errback) => {
var cmd = `pkg-config --variable=${variable} bash-completion`;
debug('cmd', cmd);
exec(cmd, function(err, stdout, stderr) {
if (err) {
// silently fail if pkg-config bash-completion returns an error,
// meaning bash-completion is either not installed or misconfigured
// with PKG_CONFIG_PATH
return r();
}
stdout = stdout.trim();
debug('Got %s for %s', stdout, variable);
r(stdout);
});
});
}

// Returns the pkg-config variable for "completionsdir" and bash-completion
completionsdir() {
debug('Asking pkg-config for completionsdir');
return this.pkgconfig('completionsdir');
}

// Returns the pkg-config variable for "compatdir" and bash-completion
compatdir() {
debug('Asking pkg-config for compatdir');
return this.pkgconfig('compatdir');
}
}

0 comments on commit 9b83d76

Please sign in to comment.