Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bash-completion code #125

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/jupyter-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ if [[ -n ${ZSH_VERSION-} ]]; then
autoload -Uz bashcompinit && bashcompinit
fi

_jupyter()
_jupyter_get_flags()
{
local url=$1
local var=$2
local dash=$3
if [[ "$url $var" == $__jupyter ]]; then
opts=$__jupyter
if [[ "$url $var" == $__jupyter_complete_last ]]; then
opts=$__jupyter_complete_last_res
return
fi
# matplotlib and profile don't need the = and the
# version without simplifies the special cased completion
opts=$(jupyter ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/<.*//" -e "s/[^=]$/& /" -e "$ s/^/\n-h\n--help\n--help-all\n/")
__jupyter="$url $var"
__jupyter="$opts"
__jupyter_complete_last="$url $var"
__jupyter_complete_last_res="$opts"
}

_jupyter()
Expand All @@ -26,11 +26,11 @@ _jupyter()
local prev=${COMP_WORDS[COMP_CWORD - 1]}
local subcommands="notebook qtconsole console nbconvert kernelspec trust "
local opts="help"
if [ -z "$__jupyter" ]; then
_jupyter baseopts
__jupyter="${opts}"
if [ -z "$__jupyter_complete_baseopts" ]; then
_jupyter_get_flags baseopts
__jupyter_complete_baseopts="${opts}"
fi
local baseopts="$__jupyter"
local baseopts="$__jupyter_complete_baseopts"
local mode=""
for i in "${COMP_WORDS[@]}"; do
[ "$cur" = "$i" ] && break
Expand All @@ -47,15 +47,15 @@ _jupyter()
if [[ ${cur} == -* ]]; then
case $mode in
"notebook" | "qtconsole" | "console" | "nbconvert")
_jupyter $mode
_jupyter_get_flags $mode
opts=$"${opts} ${baseopts}"
;;
"kernelspec")
if [[ $COMP_CWORD -ge 3 ]]; then
# 'history trim' and 'history clear' covered by next line
_jupyter $mode\ "${COMP_WORDS[2]}"
_jupyter_get_flags $mode\ "${COMP_WORDS[2]}"
else
_jupyter $mode
_jupyter_get_flags $mode

fi
opts=$"${opts}"
Expand Down