Skip to content

Commit

Permalink
bash: handle semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed Jul 23, 2018
1 parent 4c7bce2 commit 51f1de7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/cli.js
Expand Up @@ -14,8 +14,6 @@ if (process.env.TABTAB_DEBUG) {
flags: 'a+'
});

string replace -r "/.*" "" -- $location
set location (string split "/" -- $location)[1]
debug.log = (...args) => {
args = args.map(arg => {
if (typeof arg === 'string') return arg;
Expand All @@ -30,14 +28,15 @@ if (argv[0] === 'completion' && !env.complete) {
return console.log('do nothing');
}

console.error(env);
if (argv[0] === 'completion' && env.complete) {
if (/^--/.test(env.prev)) {
tabtab.log(['--help', '--foo', '--bar'], env);
return;
}

if (env.prev === 'tabtab') {
tabtab.log(['someCommand', 'anotherOne'], env);
tabtab.log(['someCommand', 'anotherOne', 'generator:app', 'generator:view'], env);
return;
}

Expand All @@ -50,4 +49,9 @@ if (argv[0] === 'completion' && env.complete) {
tabtab.log(['is', 'this', 'just', 'fantasy'], env);
return;
}

if (env.prev === 'generator') {
tabtab.log(['generator\:app', 'generator\:view', 'generator\:foo', 'generator\:meow'], env);
return;
}
}
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -10,7 +10,9 @@
"watch": "npm-watch",
"prettier": "prettier -l '{lib,test}/**/*.js'",
"quick-test": "DEBUG='tabtab*' node test/fixtures/installer-install.js",
"bash-quick-test": "DEBUG=tabtab* COMP_CWORD='2' COMP_LINE='tabtab foo' COMP_POINT='10' tabtab completion -- tabtab foo"
"bash-quick-test": "DEBUG=tabtab* COMP_CWORD='2' COMP_LINE='tabtab foo' COMP_POINT='10' tabtab completion -- tabtab foo",
"just:a:test": "echo just a test",
"just:a:test2": "echo just a test"
},
"watch": {
"test": "{lib,test}/**/*.js"
Expand Down
5 changes: 4 additions & 1 deletion scripts/bash.sh
Expand Up @@ -3,7 +3,7 @@ if type complete &>/dev/null; then
_{pkgname}_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -w words -i cword
_get_comp_words_by_ref -n = -n @ -n : -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
Expand All @@ -16,6 +16,9 @@ if type complete &>/dev/null; then
{completer} completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
if type __ltrim_colon_completions &>/dev/null; then
__ltrim_colon_completions "${words[cword]}"
fi
}
complete -o default -F _{pkgname}_completion {pkgname}
fi
Expand Down

0 comments on commit 51f1de7

Please sign in to comment.