Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ const debug = tabtabDebug('tabtab');
*/
const install = async (options = { name: '', completer: '' }) => {
const { name, completer } = options;
let { completeCmd } = options;
if (!name) throw new TypeError('options.name is required');
if (!completer) throw new TypeError('options.completer is required');
if (!completeCmd) {
completeCmd = 'completion'
}

return prompt().then(({ location }) =>
installer.install({
name,
completer,
completeCmd,
location
})
);
Expand Down
7 changes: 6 additions & 1 deletion lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const writeToTabtabScript = async ({ name }) => {
* - name: The package configured for completion
* - completer: The binary that will act as the completer for `name` program
*/
const writeToCompletionScript = ({ name, completer }) => {
const writeToCompletionScript = ({ name, completer, completeCmd }) => {
const filename = untildify(
path.join(COMPLETION_DIR, `${name}.${shellExtension()}`)
);
Expand All @@ -249,6 +249,7 @@ const writeToCompletionScript = ({ name, completer }) => {
filecontent
.replace(/\{pkgname\}/g, name)
.replace(/{completer}/g, completer)
.replace(/{completeCmd}/g, completeCmd)
// on Bash on windows, we need to make sure to remove any \r
.replace(/\r?\n/g, '\n')
)
Expand Down Expand Up @@ -289,6 +290,10 @@ const install = async (options = { name: '', completer: '', location: '' }) => {
throw new Error('options.location is required');
}

if (!options.completeCmd) {
options = {...options, completeCmd: 'completion'};
}

await Promise.all([
writeToShellConfig(options),
writeToTabtabScript(options),
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if type complete &>/dev/null; then
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
{completer} completion -- "${words[@]}" \
{completer} {completeCmd} -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
if type __ltrim_colon_completions &>/dev/null; then
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/fish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function _{pkgname}_completion
set cursor (commandline -C)
set words (node -pe "'$cmd'.split(' ').length")

set completions (eval env DEBUG=\"" \"" COMP_CWORD=\""$words\"" COMP_LINE=\""$cmd \"" COMP_POINT=\""$cursor\"" {completer} completion -- $cmd)
set completions (eval env DEBUG=\"" \"" COMP_CWORD=\""$words\"" COMP_LINE=\""$cmd \"" COMP_POINT=\""$cursor\"" {completer} {completeCmd} -- $cmd)

for completion in $completions
echo -e $completion
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if type compdef &>/dev/null; then
local reply
local si=$IFS

IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {completer} completion -- "${words[@]}"))
IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {completer} {completeCmd} -- "${words[@]}"))
IFS=$si

_describe 'values' reply
Expand Down