##// END OF EJS Templates
fix profile subcommand completion
Julian Taylor -
Show More
@@ -1,89 +1,90 b''
1 # load with: . ipython-completion.bash
1 # load with: . ipython-completion.bash
2
2
3 _ipython_get_flags()
3 _ipython_get_flags()
4 {
4 {
5 local url=$1
5 local url=$1
6 local var=$2
6 local var=$2
7 local dash=$3
7 local dash=$3
8 if [[ "$url $var" == $__ipython_complete_last ]]; then
8 if [[ "$url $var" == $__ipython_complete_last ]]; then
9 opts=$__ipython_complete_last_res
9 opts=$__ipython_complete_last_res
10 return
10 return
11 fi
11 fi
12 opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/=.*//;s/ <.*//")
12 opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/=.*//;s/ <.*//")
13 __ipython_complete_last="$url $var"
13 __ipython_complete_last="$url $var"
14 __ipython_complete_last_res="$opts"
14 __ipython_complete_last_res="$opts"
15 }
15 }
16
16
17 _ipython()
17 _ipython()
18 {
18 {
19 local cur=${COMP_WORDS[COMP_CWORD]}
19 local cur=${COMP_WORDS[COMP_CWORD]}
20 local prev=${COMP_WORDS[COMP_CWORD - 1]}
20 local prev=${COMP_WORDS[COMP_CWORD - 1]}
21 local subcommands="notebook qtconsole console kernel profile locate"
21 local subcommands="notebook qtconsole console kernel profile locate"
22 local opts=""
22 local opts=""
23 if [ -z "$__ipython_complete_baseopts" ]; then
23 if [ -z "$__ipython_complete_baseopts" ]; then
24 _ipython_get_flags core.shellapp "shell_flags.keys()" "--"
24 _ipython_get_flags baseopts
25 __ipython_complete_baseopts="${opts}"
25 __ipython_complete_baseopts="${opts}"
26 fi
26 fi
27 local baseopts="$__ipython_complete_baseopts"
27 local baseopts="$__ipython_complete_baseopts"
28 local mode=""
28 local mode=""
29 for i in "${COMP_WORDS[@]}"; do
29 for i in "${COMP_WORDS[@]}"; do
30 [ "$cur" = "$i" ] && break
30 [ "$cur" = "$i" ] && break
31 if [[ ${subcommands} == *${i}* ]]; then
31 if [[ ${subcommands} == *${i}* ]]; then
32 mode="$i"
32 mode="$i"
33 break
33 break
34 elif [[ ${i} == "--"* ]]; then
34 elif [[ ${i} == "--"* ]]; then
35 mode="nosubcommand"
35 mode="nosubcommand"
36 break
36 break
37 fi
37 fi
38 done
38 done
39
39
40 if [[ ${cur} == -* ]]; then
40 if [[ $mode == "profile" ]]; then
41 opts="list create"
42 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
43 elif [[ ${cur} == -* ]]; then
41 if [[ $mode == "notebook" ]]; then
44 if [[ $mode == "notebook" ]]; then
42 _ipython_get_flags notebook
45 _ipython_get_flags notebook
43 opts=$"${opts} ${baseopts}"
46 opts=$"${opts} ${baseopts}"
44 elif [[ $mode == "qtconsole" ]]; then
47 elif [[ $mode == "qtconsole" ]]; then
45 _ipython_get_flags qtconsole
48 _ipython_get_flags qtconsole
46 opts="${opts} ${baseopts}"
49 opts="${opts} ${baseopts}"
47 elif [[ $mode == "console" ]]; then
50 elif [[ $mode == "console" ]]; then
48 _ipython_get_flags console
51 _ipython_get_flags console
49 elif [[ $mode == "kernel" ]]; then
52 elif [[ $mode == "kernel" ]]; then
50 _ipython_get_flags kernel
53 _ipython_get_flags kernel
51 opts="${opts} ${baseopts}"
54 opts="${opts} ${baseopts}"
52 elif [[ $mode == "profile" ]]; then
53 opts="list create"
54 elif [[ $mode == "locate" ]]; then
55 elif [[ $mode == "locate" ]]; then
55 opts=""
56 opts=""
56 else
57 else
57 opts=$baseopts
58 opts=$baseopts
58 fi
59 fi
59 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
60 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
60 return 0
61 return 0
61 elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then
62 elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then
62 _ipython_get_flags core.shellapp InteractiveShellApp.pylab.values
63 _ipython_get_flags core.shellapp InteractiveShellApp.pylab.values
63 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
64 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
64 elif [[ ${prev} == "--profile"* ]]; then
65 elif [[ ${prev} == "--profile"* ]]; then
65 if [ -z "$__ipython_complete_profiles" ]; then
66 if [ -z "$__ipython_complete_profiles" ]; then
66 __ipython_complete_profiles=$(cat <<EOF | python -
67 __ipython_complete_profiles=$(cat <<EOF | python -
67 try:
68 try:
68 import IPython.core.profileapp
69 import IPython.core.profileapp
69 for k in IPython.core.profileapp.list_bundled_profiles():
70 for k in IPython.core.profileapp.list_bundled_profiles():
70 print "%s" % k,
71 print "%s" % k,
71 p = IPython.core.profileapp.ProfileList()
72 p = IPython.core.profileapp.ProfileList()
72 for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir):
73 for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir):
73 print "%s" % k,
74 print "%s" % k,
74 except:
75 except:
75 pass
76 pass
76 EOF
77 EOF
77 )
78 )
78 fi
79 fi
79 COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) )
80 COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) )
80 else
81 else
81 if [ -z "$mode" ]; then
82 if [ -z "$mode" ]; then
82 COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) )
83 COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) )
83 else
84 else
84 COMPREPLY=( $(compgen -f -- ${cur}) )
85 COMPREPLY=( $(compgen -f -- ${cur}) )
85 fi
86 fi
86 fi
87 fi
87
88
88 }
89 }
89 complete -o default -F _ipython ipython
90 complete -o default -F _ipython ipython
General Comments 0
You need to be logged in to leave comments. Login now