python, pydoc: Add module completion.

This commit is contained in:
Ville Skyttä 2013-02-02 10:46:12 +02:00
parent a77d3d5505
commit 0e8d34e6bd
2 changed files with 13 additions and 2 deletions

View File

@ -23,8 +23,9 @@ _pydoc()
fi fi
COMPREPLY=( $( compgen -W 'keywords topics modules' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'keywords topics modules' -- "$cur" ) )
local python=python; [[ $1 == *3* ]] && python=python3
_xfunc python _python_modules $python
_filedir py _filedir py
# TODO: more completions: modules, ...
} && } &&
complete -F _pydoc pydoc pydoc3 complete -F _pydoc pydoc pydoc3

View File

@ -1,12 +1,22 @@
# bash completion for python -*- shell-script -*- # bash completion for python -*- shell-script -*-
_python_modules()
{
COMPREPLY+=( $( compgen -W "$( ${1:-python} -c 'import pkgutil
for mod in pkgutil.iter_modules(): print(mod[1])' )" 2>/dev/null -- "$cur" ) )
}
_python() _python()
{ {
local cur prev words cword local cur prev words cword
_init_completion || return _init_completion || return
case $prev in case $prev in
-'?'|-h|--help|-V|--version|-c|-m) -'?'|-h|--help|-V|--version|-c)
return 0
;;
-m)
_python_modules "$1"
return 0 return 0
;; ;;
-Q) -Q)