Skip to content

Commit

Permalink
feat(description): Handle zsh description using _describe fn
Browse files Browse the repository at this point in the history
Fix #19 #21
  • Loading branch information
mklabs committed May 19, 2016
1 parent e4423f8 commit 6de7ca1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 6 additions & 3 deletions lib/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ class Complete extends EventEmitter {

var shell = (process.env.SHELL || '').split('/').slice(-1)[0];

This comment has been minimized.

Copy link
@binduwavell

binduwavell May 30, 2016

Collaborator

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.

This comment has been minimized.

Copy link
@mklabs

mklabs May 30, 2016

Author Owner

I thought about adding --zsh, --bash, --fish options. For now, I just implemented --auto one which use this SHELL env var.

We may use process.env.TABTAB_SHELL || process.env.SHELL || '' to be safer in auto mode.

Did you get any inconsistent result because of this ? I don't see how and why we would redefine the SHELL to force another installation.


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;
Expand All @@ -224,7 +227,7 @@ class Complete extends EventEmitter {

return {
name: name,
description: desc === name ? 'tabtab' : desc
description: desc === name ? 'description for ' + name : desc
};
}

Expand Down
23 changes: 11 additions & 12 deletions scripts/zsh.sh
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-###

0 comments on commit 6de7ca1

Please sign in to comment.