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

feat: add autocomplete #333

Closed
wants to merge 2 commits into from
Closed

feat: add autocomplete #333

wants to merge 2 commits into from

Conversation

kakhaUrigashvili
Copy link
Contributor

@kakhaUrigashvili kakhaUrigashvili commented Nov 5, 2020

to Add

brew install bash-completion

And the then add the following line to ~/.bash_profile or ~/.bashrc:

[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Enable

ask autocomplete setup; source ~/.bash_profile

to Remove

ask autocomplete cleanup

@kakhaUrigashvili kakhaUrigashvili linked an issue Nov 6, 2020 that may be closed by this pull request
@kakhaUrigashvili kakhaUrigashvili marked this pull request as ready for review November 6, 2020 04:57
@kakhaUrigashvili kakhaUrigashvili force-pushed the autocomplete branch 4 times, most recently from 02cbcdf to 06b4833 Compare November 11, 2020 19:34
lib/commands/smapi/smapi-commander.js Show resolved Hide resolved
this.autoCompleteHintsFile = path.join(__dirname, 'autocomplete-hints.json');
}

_getAutoCompleteOptions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, should this func be renamed to _getAutoCompleteCmd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why cmd? it just loads auto complete options tree.
{
smapi: [commandOne, commandTwo...]
...
}

docs/concepts/Autocompletion.md Outdated Show resolved Hide resolved
*/
setUpAutoComplete() {
this.reloadAutoCompleteHints();
this._withProcessExitDisabled(() => this.completion.setupShellInitFile());
Copy link
Contributor

Choose a reason for hiding this comment

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

II think we need a try catch to cover this setupShellInitFile function, as suggested by the user https://github.com/f/omelette#automated-install. This step has too many potential problems depending on user's machine.

We need to do the cleanup if it fails, and pop up the message for the failure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What type of clean up? How can we know what needs to be cleaned up? If this steps fails it will show user the error message from omelette. What extra can we do in try and catch except of rethrowing the error?

Copy link
Contributor

Choose a reason for hiding this comment

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

When i run in windows here is the result:

PS D:\Github\ask-cli> ask autocomplete setup
D:\Github\ask-cli\node_modules\omelette\src\omelette.js:189
          throw new Error('Shell could not be detected');
          ^

Error: Shell could not be detected
    at Omelette.getActiveShell (D:\Github\ask-cli\node_modules\omelette\src\omelette.js:189:17)
    at Omelette.getDefaultShellInitFile (D:\Github\ask-cli\node_modules\omelette\src\omelette.js:210:35)
    at Omelette.setupShellInitFile (D:\Github\ask-cli\node_modules\omelette\src\omelette.js:238:42)
    at D:\Github\ask-cli\lib\commands\autocomplete\helper.js:52:61
    at Helper._withProcessExitDisabled (D:\Github\ask-cli\lib\commands\autocomplete\helper.js:35:9)
    at Helper.setUpAutoComplete (D:\Github\ask-cli\lib\commands\autocomplete\helper.js:52:14)
    at Command.<anonymous> (D:\Github\ask-cli\lib\commands\autocomplete\index.js:29:20)
    at Command.listener (D:\Github\ask-cli\node_modules\commander\index.js:370:29)
    at Command.emit (events.js:314:20)
    at Command.EventEmitter.emit (domain.js:486:12)

Should we pre-check the OS? And give a good message if it falls through?

@@ -0,0 +1,29 @@
#!/usr/bin/env node
Copy link
Contributor

Choose a reason for hiding this comment

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

my biggest question would be can we save this registry step each time a new command is created? I know this is a subcommand, but is it still possible to load from the main commander object? Based on the current cmd structure, we only need it for ask ,ask smapi, ask utils, ask skill. Is it possible to iterate the command list in bin folder, and dynamically load them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cannot think of a way. Do you know a way?

@doiron
Copy link
Contributor

doiron commented Apr 28, 2022

will need to import these changes into the new ask-cli code base. closing this PR for now issue 17 is still open

@doiron doiron closed this Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Tab-completion for bash, zsh & powershell
3 participants