From faddf9dbb17fc47e5ae9e91bc7ea24a523c799c4 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 10 Oct 2022 20:29:51 +0200 Subject: [PATCH] zsh:funcs: Add pyhelp to display python help pages --- .config/zsh/zshrc.d/40-functions.zsh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 1fc93c7..abe5193 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -589,3 +589,29 @@ tag() { env TMSU_DB="$db" tmsu "$@" } + +# Display the help for a given python module/function/etc. Try to guess when +# something needs an import. +pyhelp() { + local py_exec import_statement + + if (( $+commands[python] )); then + py_exec=python + elif (( $+commands[python3] )); then + py_exec=python3 + elif (( $+commands[python2] )); then + py_exec=python2 + else + print >&2 "Python not installed." + return 1 + fi + + for arg; do + import_statement= + if [[ $arg =~ '^([^.]*)\.' ]]; then + import_statement="import $match[1]; " + fi + + $py_exec -c "${import_statement}help($arg)" + done +}