New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zsh auto completion #1292
zsh auto completion #1292
Changes from 2 commits
f058d06
40be95d
48f62fa
aab0387
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
###-begin-{{app_name}}-completions-### | ||
# | ||
# yargs command completion script | ||
# | ||
# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc | ||
# or {{app_path}} {{completion_command}} >> ~/.zsh_profile on OSX. | ||
# | ||
_{{app_name}}_yargs_completions() | ||
{ | ||
local reply | ||
local si=$IFS | ||
IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "$\{words[@]\}")) | ||
IFS=$si | ||
_describe 'values' reply | ||
} | ||
compdef _{{app_name}}_yargs_completions {{app_name}} | ||
###-end-{{app_name}}-completions-### |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,8 +79,10 @@ module.exports = function completion (yargs, usage, command) { | |
|
||
// generate the completion script to add to your .bashrc. | ||
self.generateCompletionScript = function generateCompletionScript ($0, cmd) { | ||
let zshShell = process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
|
||
let script = fs.readFileSync( | ||
path.resolve(__dirname, '../completion.sh.hbs'), | ||
path.resolve(__dirname, zshShell ? '../completion.zsh.hbs' : '../completion.sh.hbs'), | ||
'utf-8' | ||
) | ||
const name = path.basename($0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,10 +196,21 @@ describe('Completion', () => { | |
}) | ||
|
||
describe('generateCompletionScript()', () => { | ||
it('replaces application variable with $0 in script', () => { | ||
it('replaces application variable with $0 in script (bash)', () => { | ||
process.env.SHELL = '/bin/bash' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this approach 👍 |
||
const r = checkUsage(() => yargs([]) | ||
.showCompletionScript(), ['ndm']) | ||
|
||
r.logs[0].should.match(/bashrc/) | ||
r.logs[0].should.match(/ndm --get-yargs-completions/) | ||
}) | ||
|
||
it('replaces application variable with $0 in script (zsh)', () => { | ||
process.env.SHELL = '/bin/zsh' | ||
const r = checkUsage(() => yargs([]) | ||
.showCompletionScript(), ['ndm']) | ||
|
||
r.logs[0].should.match(/zshrc/) | ||
r.logs[0].should.match(/ndm --get-yargs-completions/) | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, at the end of the day this isn't too far off bash completion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not to much of a difference really.