Created
January 30, 2014 00:20
-
-
Save nicolasramy/8700101 to your computer and use it in GitHub Desktop.
Simple bash_completion file: pip, venv-* functions. (venv-functions details: https://gist.github.com/nicolasramy/6438236#file-bash_functions_python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_pip_completion() { | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
first="${COMP_WORDS[0]}" | |
commands=$($first --help | awk '/Commands\:/,/General Options\:/' | \ | |
\grep -E -o "^\s{2}\w*" | tr -d ' ') | |
opts=$($first --help | \grep -E -o "((-\w{1}|--(\w|-)*=?)){1,2}") | |
if [ $COMP_CWORD == 1 ] ; then | |
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) | |
return 0 | |
fi | |
if [[ ${cur} == -* ]] ; then | |
local command_opts=$($first $prev --help | \ | |
\grep -E -o "((-\w{1}|--(\w|-)*=?)){1,2}") | |
COMPREPLY=( $(compgen -W "${command_opts}" -- ${cur}) ) | |
return 0 | |
fi | |
} | |
complete -o default -F _pip_completion pip | |
complete -o default -F _pip_completion pip2 | |
complete -o default -F _pip_completion pip3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_list_virtual_envs() { | |
local choix selection | |
case "$COMP_CWORD" in | |
# On 1st parameter, list '~/.virtualenvs' folder | |
1) | |
available_envs=$( ls ~/.virtualenvs/ ) | |
;; | |
*) | |
words=() | |
;; | |
esac | |
# Create list choice | |
selection=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $( compgen -W '$available_envs' -- $selection ) ) | |
} | |
complete -F _list_virtual_envs venv-activate | |
complete -F _list_virtual_envs venv-remove |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to make it available in /etc/bash_completion.d/