gtalarico / pipenv-pipes

A PipEnv Environment Switcher
https://pipenv-pipes.readthedocs.io
MIT License
134 stars 29 forks source link

Shell Competion #10

Closed jonatasbaldin closed 6 years ago

jonatasbaldin commented 6 years ago

Description

It would be very nice to have Shell Completion, like virtualenvwrapper!

What I Did

I made a small script that runs on BASH and ZSH.

$ cat pipenv-pipes-completion.sh

# Shell completion for pipenv-pipes

export BASE_SHELL=$(basename $SHELL)
export DEFAULT_HOME="$HOME/.virtualenvs"

if [[ "$BASE_SHELL" == "zsh" ]] ; then
  autoload bashcompinit && bashcompinit
fi

_pipenv-pipes_completions() {
  COMPREPLY=($(compgen -W "$(ls $DEFAULT_HOME $PIPENV_HOME)" -- "${COMP_WORDS[1]}"))
}

complete -F _pipenv-pipes_completions pipes
$ source ./pipenv-pipes-completion.sh
$ pipes <tab><tab>

What do you think about it? Could we put somewhere in the code base or maybe as a script some where and put the activation instructions on README?

Cheers,

gtalarico commented 6 years ago

Thanks for sending this - would be great to add autocompletion.

~I would be happy to add this to the docs if you could send a PR.~ I will test this out and see if I can put together something for fish as well.

PS: I was able to get this to work with bash and fish. I added a small helper function within pipes to provide the envnames, so we can keep the autocompletion scripts as simple as possible

jonatasbaldin commented 6 years ago

Yay, that's awesome, let's merge it? :shipit:

gtalarico commented 6 years ago

Merged and released https://pypi.org/project/pipenv-pipes/0.6.0/#description