Skip to content
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

Add inspec env command to configure shell tab-completion #896

Merged
merged 1 commit into from
Aug 10, 2016

Conversation

stevendanna
Copy link
Contributor

@stevendanna stevendanna commented Aug 9, 2016

This adds a new subcommand:

inspec env [SHELL]

which outputs a shell-appropriate completion script that the user can
source into their shell:

eval "$(inspec env SHELL)"

Currently, we provide completions for ZSH and Bash. The completion
scripts are generated from the data Thor collects.

If the user doesn't provide SHELL we attempt to detect what the user's
shell may be using a number of methods.

Fixes #607

Signed-off-by: Steven Danna steve@chef.io


def detect
# Most of our detection code assumes a unix-like environment
return nil if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May it make sense to output a warning? Otherwise the user may be confused that nothing has been executed?

@chris-rock
Copy link
Contributor

chris-rock commented Aug 9, 2016

@stevendanna great work. Bash completion works like a charm. I've some troubles with zsh and get the following errors:

eval "$(inspec env zsh)"
zsh: parse error near `>'

My generated content is available here: https://gist.github.com/chris-rock/a30592b0b82d13136772c10162dc5752

if @detected
$stderr.puts '# Unable to automatically detect shell and no shell was provided.'
end
$stderr.puts <<EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

@chris-rock
Copy link
Contributor

Awesome implementation @stevendanna LGTM once the zsh is working

@stevendanna
Copy link
Contributor Author

@chris-rock I think ZSH should be working now. The issue was we weren't escaping the description text and you had plugins that had commands with ' in their description. Now we use shellwords to escape any special characters in the description. Let me know if it works for you.

@chris-rock
Copy link
Contributor

@stevendanna works like a charm now!

@stevendanna stevendanna changed the title WIP: Add inspec env command to configure shell tab-completion Add inspec env command to configure shell tab-completion Aug 10, 2016
This adds a new subcommand:

   inspec env [SHELL]

which outputs a shell-appropriate completion script that the user can
source into their shell:

   eval "$(inspec env SHELL)"

Currently, we provide completions for ZSH and Bash. The completion
scripts are generated from the data Thor collects.

If the user doesn't provide SHELL we attempt to detect what the user's
shell may be using a number of methods.

Signed-off-by: Steven Danna <steve@chef.io>
@stevendanna
Copy link
Contributor Author

Merging this despite failing tests since TravisCI seems to be having an incident of some sort.

@stevendanna stevendanna merged commit e073a63 into master Aug 10, 2016
@chris-rock chris-rock modified the milestone: 0.30.0 Aug 10, 2016
@chris-rock chris-rock modified the milestone: 0.30.0 Aug 10, 2016
@stevendanna stevendanna deleted the ssd/tab-complete branch August 11, 2016 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants