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