Skip to content

Commit

Permalink
fix bash-completion code
Browse files Browse the repository at this point in the history
When transferring from ipython, the jupyter-completion.bash file was
not adapted correctly, leading to a segfault. This patch fixes the
issue.
  • Loading branch information
andram committed Feb 7, 2018
1 parent 7f1430f commit 812e613
Showing 1 changed file with 12 additions and 12 deletions.
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

0 comments on commit 812e613

Please sign in to comment.