jezdez / envdir

A Python port of daemontools' envdir.
https://envdir.readthedocs.io/
MIT License
229 stars 28 forks source link

autocomplete stops working #54

Closed AlJohri closed 7 years ago

AlJohri commented 7 years ago

I've been running rake tasks with envdir like so:

envdir envs/prod rake blahblahblah

For some reason, rake stops autocompleting when used with envdir.

Do you think this has to do with envdir or the way the autocomplete script is written?

blueyed commented 7 years ago

This is a configuration of your shell, where you need to make it consider envdir ... to be handled like with sudo etc.

See https://github.com/blueyed/oh-my-zsh/commit/59d43ad766c8625fcd7e6373e80a8ab39288ac36 for my completion script that I am using for Zsh.

Closing this issue, since it's not an issue of envdir - but we could consider shipping some completion scripts by default, and/or I could add mine to https://github.com/zsh-users/zsh-completions.

AlJohri commented 7 years ago

Hi @blueyed,

I'm having some issues using the envdir zsh completion script.

It first tries to autocomplete an " -- external command --" which seems correct but after that it only autocompletes a "-- file --" not taking into account the external command. This does not work for commands such as rake, make, rails, django-admin, etc.

I've created a test case that demonstrates the issue in detail.


Setup

Directory Structure

Contains a Makefile, Rakefile, and two environments (env and prod) with a single environment variable SOMEVAR.

➜   test_envdir_autocomplete  tree
.
├── Makefile
├── Rakefile
└── envs
    ├── dev
    │   └── SOMEVAR
    └── prod
        └── SOMEVAR

3 directories, 4 files

Rakefile

➜   test_envdir_autocomplete  cat Rakefile
desc "hello"
task :hello do
    puts "hello from rake! SOMEVAR is #{ENV['SOMEVAR']}"
end

desc "goodbye"
task :goodbye do
    puts "goodbye from rake! SOMEVAR is #{ENV['SOMEVAR']}"
end

Makefile

➜   test_envdir_autocomplete  cat Makefile
.PHONY: hello goodbye

hello:
    @echo "hello frome make. SOMEVAR is $(SOMEVAR)"

goodbye:
    @echo "goodbye frome make. SOMEVAR is $(SOMEVAR)"

Environments

SOMEVAR is true in dev and false in prod.

➜   test_envdir_autocomplete  tail envs/**/*(.)
==> envs/dev/SOMEVAR <==
true

==> envs/prod/SOMEVAR <==
false

Demo

As you can see from the screenshots below, the envdir completion script is picking up -- file -- as opposed to -- make targets -- or -- rake target --.

Without Envdir

Typing make, space, and <TAB>. screen shot 2016-10-12 at 12 25 44 am

Typing rake, space, and <TAB>. screen shot 2016-10-12 at 12 27 07 am

With Envdir

Typing envdir envs/dev, space, and <TAB>. screen shot 2016-10-12 at 12 29 23 am

Typing envdir envs/dev make, space, and <TAB>. screen shot 2016-10-12 at 12 28 12 am

Typing envdir envs/dev rake, space, and <TAB>. screen shot 2016-10-12 at 12 28 04 am


Configuration

➜   test_envdir_autocomplete  zsh --version
zsh 5.2 (x86_64-apple-darwin15.0.0)
➜   test_envdir_autocomplete  brew list --versions | grep zsh
zsh 5.2
zsh-syntax-highlighting 0.4.1

Using zprezto which has zsh-completions as a git submodule.

blueyed commented 7 years ago

Thanks for the detailed report.. I was aware of this issue (but forgot about it). It can be reproduced by envdir envdir ls -<tab>. The fix is to use _precommand instead of _normal. Updated: https://github.com/blueyed/oh-my-zsh/blob/master/functions/_envdir.

AlJohri commented 7 years ago

thanks @blueyed! just tested and confirmed this works. I'd love to get this merged into zsh-completions

blueyed commented 7 years ago

@AlJohri There you go: https://github.com/zsh-users/zsh-completions/pull/459