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

ddev should support zsh autocomplete #327

Closed
rickmanelius opened this issue Jun 15, 2017 · 48 comments · Fixed by #2234
Closed

ddev should support zsh autocomplete #327

rickmanelius opened this issue Jun 15, 2017 · 48 comments · Fixed by #2234
Labels
Prioritized We expect to do this in an upcoming release
Milestone

Comments

@rickmanelius
Copy link
Contributor

What happened (or feature request):

  • Feature request.

What you expected to happen:

Related source links or issues:

@rfay
Copy link
Member

rfay commented Jun 15, 2017

Was the title of this supposed to say 'zsh' instead of 'bash'?

@rickmanelius rickmanelius changed the title ddev should support bash autocomplete ddev should support zsh autocomplete Jun 15, 2017
@rickmanelius
Copy link
Contributor Author

Yes :)

@rickmanelius
Copy link
Contributor Author

Love the idea, but this isn't a priority at this time.

@rfay
Copy link
Member

rfay commented Dec 22, 2018

Reopening, because there are zsh users out there and they might like it. Shouldn't be that hard, depending on the level of support in cobra now.

@KaffDaddy
Copy link
Contributor

KaffDaddy commented Apr 10, 2019

Maybe you can use in the meantime https://github.com/zsh-users/zsh-autosuggestions for autocomplete suggestions based on your history?
I use it with oh-my-zsh as plugin.
Download it with git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions and add zsh-autosuggestions in the plugins section of your .zshrc file.

@rfay
Copy link
Member

rfay commented Apr 10, 2019

Nice, thanks @KaffDaddy

@mharmuth
Copy link

ZSH will be the new standard in OSX Catalina. Would be nice if this gets implemented sooner or later ;-)

@KaffDaddy Thanks for this tip :-)

@rfay
Copy link
Member

rfay commented Aug 29, 2019

It shouldn't be too hard to add the limited support cobra offers, and I'm sure the macOS change will pressure cobra and us to get this in. It really isn't very hard from this end. Thanks for chiming in!

@rfay rfay removed the hibernate label Aug 29, 2019
@peterkraume
Copy link
Sponsor Contributor

I'd like to bump this issue. Would be really cool to have zsh autocompletion! At best including the custom commands as well.

@rfay
Copy link
Member

rfay commented Nov 18, 2019

Thanks for bumping!

@unn
Copy link
Contributor

unn commented Nov 25, 2019

Ran into this today myself after a Catalina update.

@rfay rfay added the Prioritized We expect to do this in an upcoming release label Dec 7, 2019
@karlosb
Copy link

karlosb commented Apr 28, 2020

Hi @rfay, just wondering if there has been any more updates on the auto-complete plugin? Would by really great if this is available! :-)

@rfay
Copy link
Member

rfay commented Apr 28, 2020

Thanks for checking in @karlosb ! It helps us know who wants what! It looks like the reports on spf13/cobra#107 are quite bad, and there doesn't seem to be much going on there.

spf13/cobra#646 did get pulled.

There were some issues in spf13/cobra#881 that look like they may be somewhat of a stumbling block, but it sounds like within limits the pulled PR is doing OK.

So this will be worth looking at :) Thanks!

@karlosb
Copy link

karlosb commented Apr 28, 2020

Hi @rfay many thanks for the update on this. Are you saying there is an updated version of DDEV that we can try this out?

@rfay
Copy link
Member

rfay commented Apr 28, 2020

No @karlosb it will take some work to integrate the work mentioned above, if it works out we can hope it will be in a future release.

@tgaertner
Copy link

No @karlosb it will take some work to integrate the work mentioned above, if it works out we can hope it will be in a future release.

That's great news for all the zsh Users out there :-) Very much appreciate this!

@rfay
Copy link
Member

rfay commented May 5, 2020

For those of you who use zsh, I'd love to have you try out the zsh autocomplete artifacts at #2234 (comment) - I think you'll like them.

@karlosb
Copy link

karlosb commented May 5, 2020 via email

@rfay
Copy link
Member

rfay commented May 5, 2020

@karlosb thanks for testing. As that comment says,

To test, please unzip it into your local $fpath, then rm -f ~/.zcompdump && compinit. You should then have zsh autocompletion working

@karlosb
Copy link

karlosb commented May 5, 2020 via email

@rfay
Copy link
Member

rfay commented May 5, 2020

It's an environment variable that zsh uses to figure out where it loads functions from. So echo $fpath. You'll likely want to create a new directory for now, like mkdir ~/.zshfuncs and then change your .zshrc to export fpath=(~/.zshfuncs $fpath)

This Stack Overflow may help you.

I'm a n00b to zsh, so just learning as I go along.

@karlosb
Copy link

karlosb commented May 5, 2020 via email

@felmab
Copy link

felmab commented May 5, 2020

Wow, thank you so much @rfay! Looks like it works.

@karlosb you can copy this file as ~/.oh-my-zsh/custom/plugins/ddev/_ddev and add ddev in your plugins array in ~/.zshrc. Then apparently removing .zcompdump* and lauching compinit helps. Could you please confirm you can make it work? If so, we should prepare a pull request to integrate this file as a plugin into the Oh My ZSH distribution.

@rfay
Copy link
Member

rfay commented May 5, 2020

I think we may be able to have homebrew detect oh-my-zsh and put the _ddev file there.

@karlosb
Copy link

karlosb commented May 5, 2020 via email

@felmab
Copy link

felmab commented May 6, 2020

I think we may be able to have homebrew detect oh-my-zsh and put the _ddev file there.

@rfay The usual way is to add a plugin in Oh My ZSH, which can be optionally enabled in .zshrc. Now, I guess homebrew (can't say much about it, being an Archlinux user) could display a message to explain how to enable this plugin if it detects Oh My ZSH is present, or ask users what they want to do about it. Unlike Bash, the situation can be rather complex to deal with, as the user could use plain ZSH, or one of the many ZSH distributions like Oh My ZSH.

@tgaertner
Copy link

Also use Oh My ZSH - on desktop this is maybe the most commen use case..? I can test with Oh My ZSH if there is anything to test.

@karlosb
Copy link

karlosb commented May 6, 2020

Hi @rfay @felmab

I've sorted the following:
Installed _ddev (ddev_zsh_autocompletes.zip) at both directories (as both exist):

~/.oh-my-zsh/plugins/ddev
~/.oh-my-zsh/custom/plugins/ddev

Upated ~/.zshrc file with the plugin 'ddev':

plugins=(git extract osx eecms npm node bower colored-man-pages last-working-dir colorize emoji ddev)

Also added to ~./zshrc
export fpath=(~/.zshfuncs $fpath)

Then ran the following:

source ~/.zshrc (to update Oh my zsh install)
rm -f ~/.zcompdump && compinit

Quit terminal and reloaded and tried typing:
ddev (and then tab for auto-complete)

And does not work?

@felmab
Copy link

felmab commented May 6, 2020

@karlosb

Installed _ddev (ddev_zsh_autocompletes.zip) at both directories (as both exist):

~/.oh-my-zsh/plugins/ddev
~/.oh-my-zsh/custom/plugins/ddev

You only need to install it in ~/.oh-my-zsh/custom/plugins/ddev, not sure a duplicate plugin is a good thing. ~/.oh-my-zsh/plugins/ddev should be reserved for official plugins supported by Oh My ZSH (which is not yet the case).

Upated ~/.zshrc file with the plugin 'ddev':

plugins=(git extract osx eecms npm node bower colored-man-pages last-working-dir colorize emoji ddev)

Looks good.

Also added to ~./zshrc
export fpath=(~/.zshfuncs $fpath)

You don't need that. Oh My ZSH will internally deal with fpath.

Quit terminal and reloaded and tried typing:
ddev (and then tab for auto-complete)

And does not work?

Please try hitting tab twice.

@karlosb
Copy link

karlosb commented May 6, 2020

Hi @felmab

I have removed the following folder (and it's contents ie. _ddev):
~/.oh-my-zsh/plugins/ddev

Removed the following line from ~.zshrc:
export fpath=(~/.zshfuncs $fpath)

Ran:
source ~/.zshrc

Restarted terminal.

Then tried:
ddev (and then hit tab twice for auto-complete)

Still no luck getting it to work.

Any other ideas what may be wrong?

@felmab
Copy link

felmab commented May 6, 2020

@karlosb could you give us the output of:

echo $plugins
echo $ZSH_CUSTOM

@karlosb
Copy link

karlosb commented May 6, 2020

Hi @felmab

echo $plugins:
git extract osx eecms npm node bower colored-man-pages last-working-dir colorize z emoji ddev zsh-autosuggestions
echo $ZSH_CUSTOM
/Users/my_username/.oh-my-zsh/custom

@felmab
Copy link

felmab commented May 6, 2020

@karlosb Mmmh don't know what to say but noting I have more than one .zcompdump file on my machine, the other one is called .zcompdump-MYHOSTNAME-VERSION.

@karlosb
Copy link

karlosb commented May 6, 2020 via email

@felmab
Copy link

felmab commented May 6, 2020

@karlosb

~  ddev
auth              -- A collection of authentication commands
composer          -- Executes a composer command within the web container
config            -- Create or modify a ddev project configuration in the current directory
debug             -- A collection of debugging commands
delete            -- Remove all project information (including database) for an existing proj
describe          -- Get a detailed description of a running ddev project.
exec              -- Execute a shell command in the container for a service. Uses the web ser
export-db         -- Dump a database to stdout or to a file
hostname          -- Manage your hostfile entries.
import-db         -- Import a sql archive into the project.
import-files      -- Pull the uploaded files directory of an existing project to the default 
list              -- List projects
logs              -- Get the logs from your running services.
pause             -- uses 'docker stop' to pause/stop the containers belonging to a project.
poweroff          -- Completely stop all projects and containers
pull              -- Pull files and database using a configured provider plugin.
restart           -- Restart a project or several projects.
restore-snapshot  -- Restore a project's database to the provided snapshot version.
share             -- Share project on the internet via ngrok.
snapshot          -- Create a database snapshot for one or more projects.
ssh               -- Starts a shell session in the container for a service. Uses web service 
start             -- Start a ddev project.
stop              -- Stop and remove the containers of a project. Does not lose or harm anyth
version           -- print ddev version and component versions

@karlosb
Copy link

karlosb commented May 6, 2020

Hi @felmab @rfay

Many thanks for the confirmation above.

I have it working now!

The .zcompdump files were not properly deleting from the ~/ directory with the following:
rm -f ~/.zcompdump && compinit

So I manually deleted ~/.zcompdump and two other similar files.

Ran:
compinit

Then:
source ~/.zshrc

and all is now working as expected!

@felmab
Copy link

felmab commented May 7, 2020

@rfay do you agree with the inclusion of your code into the Oh My ZSH project? Is it released under an MIT-compatible license?

@karlosb @tgaertner, could you review and approve ("+1") this pull request?

@rfay
Copy link
Member

rfay commented May 7, 2020

@felmab The autocomplete is generated and would change a bit on every release. I don't object to it being in Oh My Zsh, but OTOH, it won't automatically be maintained that way... I was assuming that homebrew or the install script (or the user) would be putting the autocomplete where it belongs.

@felmab
Copy link

felmab commented May 7, 2020

@rfay It would indeed be really cool if you decided to support both plain ZSH and Oh My ZSH.

I guess in that case you could add a ddev directory in $ZSH_CUSTOM/plugins if you detected its existence and the user agrees. However, maybe editing the plugins array should be up to the user.
Now, the installer is run as root, which makes it difficult to install it per user (Oh My ZSH is generally installed per user). I see that under Archlinux Bash completion is installed globally. One solution could be to install the plugin globally and advise the user to make a symbolic link...

@felmab
Copy link

felmab commented May 7, 2020

Actually it was really silly of me to focus on Oh My ZSH plugins, dropping the completion file somewhere in /usr/share/zsh/functions/Completion works perfectly well.

@felmab
Copy link

felmab commented May 7, 2020

/usr/local/share/zsh/site-functions also is in my fpath, even though this folder was never created.

@karlosb
Copy link

karlosb commented May 7, 2020

Hi @felmab are you still looking for me to '+1' a pull request, or have things changed? (Sorry I'm pretty new to the whole github pull/review stuff!!!).

@rfay
Copy link
Member

rfay commented May 8, 2020

So I prefer to avoid using superuser privileges on installation, so a user-local $fpath entry would be better. If there's a predictable way to put it user-local, that will be great. I don't object to figuring out how to maintain it with Oh My Zsh if that can be kept up to date, etc.

@felmab
Copy link

felmab commented May 8, 2020

Hi @felmab are you still looking for me to '+1' a pull request, or have things changed? (Sorry I'm pretty new to the whole github pull/review stuff!!!).

@karlosb I think I'll just close it since apparently DDEV installer will take care of it.

@rfay This is what my $fpath looks like (Archlinux):
$HOME/.oh-my-zsh/custom/plugins/ddev ... $HOME/.oh-my-zsh/plugins/git $HOME/.oh-my-zsh/plugins/composer $HOME/.oh-my-zsh/functions $HOME/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/functions/Calendar /usr/share/zsh/functions/Chpwd /usr/share/zsh/functions/Completion /usr/share/zsh/functions/Completion/Base /usr/share/zsh/functions/Completion/Linux /usr/share/zsh/functions/Completion/Unix /usr/share/zsh/functions/Completion/X /usr/share/zsh/functions/Completion/Zsh /usr/share/zsh/functions/Exceptions /usr/share/zsh/functions/Math /usr/share/zsh/functions/MIME /usr/share/zsh/functions/Misc /usr/share/zsh/functions/Newuser /usr/share/zsh/functions/Prompts /usr/share/zsh/functions/TCP /usr/share/zsh/functions/VCS_Info /usr/share/zsh/functions/VCS_Info/Backends /usr/share/zsh/functions/Zftp /usr/share/zsh/functions/Zle

$HOME/.oh-my-zsh/functions and $HOME/.oh-my-zsh/completions would have been good candidates but they would have to be created and the parent directory is managed by Git (~/.oh-my-zsh/custom is explicitly ignored), so back to creating a custom plugin in that case...

@felmab
Copy link

felmab commented May 8, 2020

Or adding an entry in $fpath of course.

@rfay rfay linked a pull request May 8, 2020 that will close this issue
10 tasks
@rfay
Copy link
Member

rfay commented May 8, 2020

ddev can't add an entry to $fpath in any consistent way, it would mean editing .zshrc, I don't see that happening. I do wish there weren't so many ways to do things with zsh. When #2234 gets reviews and a little more maturity, I'll try out Oh My Zsh and look at the installation options.

rfay added a commit that referenced this issue May 28, 2020
* Bump spf13/cobra to v1.0.0
* Basic generation of zsh, fish, and powershell
* Add zsh instructions to install.sh
* Make the install_ddev.sh script install zsh completions if possible
* Add docs for completions
* Create a tarball of completion scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prioritized We expect to do this in an upcoming release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants