Show More
@@ -1,100 +1,106 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 | opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/=.*//;s/ <.*//") | |
|
12 | # pylab and profile don't need the = and the | |
|
13 | # version without simplifies the special cased completion | |
|
14 | opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/<.*//" -e "s/[^=]$/& /" -e "s/^--pylab=$//" -e "s/^--profile=$/--profile /") | |
|
13 | 15 | __ipython_complete_last="$url $var" |
|
14 | 16 | __ipython_complete_last_res="$opts" |
|
15 | 17 | } |
|
16 | 18 | |
|
17 | 19 | _ipython() |
|
18 | 20 | { |
|
19 | 21 | local cur=${COMP_WORDS[COMP_CWORD]} |
|
20 | 22 | local prev=${COMP_WORDS[COMP_CWORD - 1]} |
|
21 | 23 | local subcommands="notebook qtconsole console kernel profile locate" |
|
22 | 24 | local opts="" |
|
23 | 25 | if [ -z "$__ipython_complete_baseopts" ]; then |
|
24 | 26 | _ipython_get_flags baseopts |
|
25 | 27 | __ipython_complete_baseopts="${opts}" |
|
26 | 28 | fi |
|
27 | 29 | local baseopts="$__ipython_complete_baseopts" |
|
28 | 30 | local mode="" |
|
29 | 31 | for i in "${COMP_WORDS[@]}"; do |
|
30 | 32 | [ "$cur" = "$i" ] && break |
|
31 | 33 | if [[ ${subcommands} == *${i}* ]]; then |
|
32 | 34 | mode="$i" |
|
33 | 35 | break |
|
34 | 36 | elif [[ ${i} == "--"* ]]; then |
|
35 | 37 | mode="nosubcommand" |
|
36 | 38 | break |
|
37 | 39 | fi |
|
38 | 40 | done |
|
39 | 41 | |
|
40 | 42 | if [[ $mode == "profile" ]]; then |
|
41 | 43 | opts="list create" |
|
42 | 44 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
43 | 45 | elif [[ ${cur} == -* ]]; then |
|
44 | 46 | if [[ $mode == "notebook" ]]; then |
|
45 | 47 | _ipython_get_flags notebook |
|
46 | 48 | opts=$"${opts} ${baseopts}" |
|
47 | 49 | elif [[ $mode == "qtconsole" ]]; then |
|
48 | 50 | _ipython_get_flags qtconsole |
|
49 | 51 | opts="${opts} ${baseopts}" |
|
50 | 52 | elif [[ $mode == "console" ]]; then |
|
51 | 53 | _ipython_get_flags console |
|
52 | 54 | elif [[ $mode == "kernel" ]]; then |
|
53 | 55 | _ipython_get_flags kernel |
|
54 | 56 | opts="${opts} ${baseopts}" |
|
55 | 57 | elif [[ $mode == "locate" ]]; then |
|
56 | 58 | opts="" |
|
57 | 59 | else |
|
58 | 60 | opts=$baseopts |
|
59 | 61 | fi |
|
62 | # don't drop the trailing space | |
|
63 | local IFS=$'\t\n' | |
|
60 | 64 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
61 | 65 | return 0 |
|
62 | 66 | elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then |
|
63 | 67 | if [ -z "$__ipython_complete_pylab" ]; then |
|
64 | 68 | __ipython_complete_pylab=$(cat <<EOF | python - |
|
65 | 69 | try: |
|
66 | 70 | import IPython.core.shellapp as mod; |
|
67 | 71 | for k in mod.InteractiveShellApp.pylab.values: |
|
68 |
print "%s" % k |
|
|
72 | print "%s " % k | |
|
69 | 73 | except: |
|
70 | 74 | pass |
|
71 | 75 | EOF |
|
72 | 76 | ) |
|
73 | 77 | fi |
|
78 | local IFS=$'\t\n' | |
|
74 | 79 | COMPREPLY=( $(compgen -W "${__ipython_complete_pylab}" -- ${cur}) ) |
|
75 | 80 | elif [[ ${prev} == "--profile"* ]]; then |
|
76 | 81 | if [ -z "$__ipython_complete_profiles" ]; then |
|
77 | 82 | __ipython_complete_profiles=$(cat <<EOF | python - |
|
78 | 83 | try: |
|
79 | 84 | import IPython.core.profileapp |
|
80 | 85 | for k in IPython.core.profileapp.list_bundled_profiles(): |
|
81 |
print "%s" % k |
|
|
86 | print "%s " % k | |
|
82 | 87 | p = IPython.core.profileapp.ProfileList() |
|
83 | 88 | for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir): |
|
84 |
print "%s" % k |
|
|
89 | print "%s " % k | |
|
85 | 90 | except: |
|
86 | 91 | pass |
|
87 | 92 | EOF |
|
88 | 93 | ) |
|
89 | 94 | fi |
|
95 | local IFS=$'\t\n' | |
|
90 | 96 | COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) ) |
|
91 | 97 | else |
|
92 | 98 | if [ -z "$mode" ]; then |
|
93 | 99 | COMPREPLY=( $(compgen -f -W "${subcommands}" -- ${cur}) ) |
|
94 | 100 | else |
|
95 | 101 | COMPREPLY=( $(compgen -f -- ${cur}) ) |
|
96 | 102 | fi |
|
97 | 103 | fi |
|
98 | 104 | |
|
99 | 105 | } |
|
100 | complete -o default -F _ipython ipython | |
|
106 | complete -o default -o nospace -F _ipython ipython |
General Comments 0
You need to be logged in to leave comments.
Login now