
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
completion
Advanced tools

Completion library for words, commands, and sentences
This was built as part of foundry, a CLI utility for making releases painless.
$ git chec|
$ git checkout |
$ git checkout dev/|
dev/hello.world dev/goodbye.moon
$ git chec|dev/
$ git checkout |dev/
Install the module with: npm install completion
var Completion = require('completion');
var completion = new Completion({
git: {
checkout: function (info, cb) {
// For `git checkout dev/|`
// info.words.value = ['git', 'checkout', 'dev/']
// info.word.partialLeft = 'dev/'
getGitBranches(function (err, allBranches) {
if (err) {
return cb(err);
}
var partialLeftWord = info.word.partialLeft;
var branches = allBranches.filter(function (branch) {
// 'chec' === 'chec' (from 'checkout')
return partialLeftWord === branch.substr(0, partialLeftWord.length);
});
cb(null, branches);
});
}
}]
});
completion.complete({
// `git chec|`
line: 'git chec',
cursor: 8
}, function (err, results) {
results; // ['checkout']
});
In bash, tab completion will override the the left half of the current word.
As a result, for cases like:
$ git chec|
$ git checkout| # requires ['checkout'] to be returned
Unfortunately, while we can deal with commands, we cannot predict the values of those.
You will still be responsible for handling of right partials in the autocompleted items.
$ git checkout a|c
[
'abc', # `git checkout abc` - Checkout `abc` branch
'aaa' # `git checkout aaa c` - Chekckout `c` file from `aaa` branch
]
completion exposes the Completion constructor via its module.exports
new Completion(tree)Create a new completion instance
Object - Outline of program
git, checkout)function (info, cb)Object - Collection of distilled information
Function - Error-first callback function to run with matches
cb has a signature of function (err, results)null representing a terminal function which has no further predictive input
null for that case.completion.complete(params, cb)Get potential completion matches
Object - Information similar to that passed in by bash's tab completion
String - Input to complete against (similar to COMP_LINE)Number - Index within line of the cursor (similar to COMP_POINT)Function - Error-first callback function that receives matches
cb should have a signature of function (err, results)An example of git would be
var gitCompletion = new Completion({
git: {
// `git checkout master`
checkout: function (info, cb) {
// Get git branches and find matches
},
remote: {
// `git remote add origin git@github.com:...`
add: null, // No possible tab completion here
// `git remote rm origin`
rm: function (info, cb) {
// Get git branches and find matches
}
}
}
});
gitCompletion.complete({
// `git remo|add`
line: 'git remoadd',
cursor: 8
}, function (err, results) {
results; // ['remote']
});
gitCompletion.complete({
// `git remote |`
line: 'git remote',
cursor: 11
}, function (err, results) {
results; // ['add', 'remove']
});
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.
Support this project and others by twolfson via gittip.
As of Dec 15 2013, Todd Wolfson has released this repository and its contents to the public domain.
It has been released under the UNLICENSE.
FAQs
Completion library for CLI commands
The npm package completion receives a total of 331 weekly downloads. As such, completion popularity was classified as not popular.
We found that completion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.