-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(description): Handle zsh description using _describe fn
- Loading branch information
Showing
2 changed files
with
17 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,9 +207,12 @@ class Complete extends EventEmitter { | |
|
||
var shell = (process.env.SHELL || '').split('/').slice(-1)[0]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mklabs
Author
Owner
|
||
|
||
if (shell === 'bash' || shell === 'zsh') console.log(completions.join('\n')); | ||
if (shell === 'bash') console.log(completions.join('\n')); | ||
else if (shell === 'zsh' ) console.log(completions.map(this.completionItem).map((item) => { | ||
return `${item.name.replace(/:/g, '\\:')}:${item.description}`; | ||
}).join('\n')); | ||
else console.log(completions.map(this.completionItem).map((item) => { | ||
return `${item.name}:${item.description}` | ||
return `${item.name}:${item.description}`; | ||
}).join('\n')); | ||
|
||
return completions; | ||
|
@@ -224,7 +227,7 @@ class Complete extends EventEmitter { | |
|
||
return { | ||
name: name, | ||
description: desc === name ? 'tabtab' : desc | ||
description: desc === name ? 'description for ' + name : desc | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
###-begin-{pkgname}-completion-### | ||
_{pkgname}_completion () { | ||
local cword line point words si | ||
###-begin-yo-completion-### | ||
_yo_completion () { | ||
local cword line point words reply | ||
read -Ac words | ||
read -cn cword | ||
let cword-=1 | ||
read -l line | ||
read -ln point | ||
si="$IFS" | ||
IFS=$'\n' reply=($(COMP_CWORD="$cword" \ | ||
COMP_LINE="$line" \ | ||
COMP_POINT="$point" \ | ||
{completer} completion -- "${words[@]}" \ | ||
2>/dev/null)) || return $? | ||
IFS="$si" | ||
|
||
local si=$IFS | ||
IFS=$'\n' reply=($(COMP_CWORD="$cword" COMP_LINE="$line" COMP_POINT="$point" yo-complete completion -- "${words[@]}")) | ||
IFS=$si | ||
_describe 'values' reply | ||
} | ||
compctl -K _{pkgname}_completion {pkgname} | ||
###-end-{pkgname}-completion-### | ||
|
||
compdef _yo_completion yo | ||
###-end-yo-completion-### |
I think each shell .sh script should pass in the shell so when we perform shell specific logic we are in sync. Re checking here could result in a race condition. Imagine you start a zsh session and then redefine $SHELL in order to force the installer to perform bash installation. Now if you attempt completion you will get bogus data passed to the completion handler. Granted, this is not likely to be a common occurrence.
Alternatively, you could make sure all input from the shells and output to the shells is consistent and the completion scripts would handle the differences. Since I prefer to write JavaScript than figure out obscure shell magic in several shells, I suggest the original approach.