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