summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2013-02-02 10:46:12 +0200
committerVille Skyttä <ville.skytta@iki.fi>2013-02-02 10:46:12 +0200
commit0e8d34e6bda72787b6b9833e042d3f55d73a4288 (patch)
treeb911066bf5c275a849b3577348fa6a21de2ba731
parenta77d3d550564198c11e2b4823a53979868262a48 (diff)
downloadbash-completion-0e8d34e6bda72787b6b9833e042d3f55d73a4288.tar.gz
python, pydoc: Add module completion.
-rw-r--r--completions/pydoc3
-rw-r--r--completions/python12
2 files changed, 13 insertions, 2 deletions
diff --git a/completions/pydoc b/completions/pydoc
index c16295d7..16adb863 100644
--- a/completions/pydoc
+++ b/completions/pydoc
@@ -23,8 +23,9 @@ _pydoc()
fi
COMPREPLY=( $( compgen -W 'keywords topics modules' -- "$cur" ) )
+ local python=python; [[ $1 == *3* ]] && python=python3
+ _xfunc python _python_modules $python
_filedir py
- # TODO: more completions: modules, ...
} &&
complete -F _pydoc pydoc pydoc3
diff --git a/completions/python b/completions/python
index 969f3b93..9c7cec13 100644
--- a/completions/python
+++ b/completions/python
@@ -1,12 +1,22 @@
# 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()
{
local cur prev words cword
_init_completion || return
case $prev in
- -'?'|-h|--help|-V|--version|-c|-m)
+ -'?'|-h|--help|-V|--version|-c)
+ return 0
+ ;;
+ -m)
+ _python_modules "$1"
return 0
;;
-Q)