Show More
@@ -1,131 +1,131 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 | 46 | |
|
47 | 47 | if [[ ${cur} == -* ]]; then |
|
48 | 48 | case $mode in |
|
49 | 49 | "notebook" | "qtconsole" | "console" | "kernel" | "nbconvert") |
|
50 | 50 | _ipython_get_flags $mode |
|
51 | 51 | opts=$"${opts} ${baseopts}" |
|
52 | 52 | ;; |
|
53 | 53 | "locate" | "profile") |
|
54 | 54 | _ipython_get_flags $mode |
|
55 | 55 | ;; |
|
56 | 56 | "history") |
|
57 |
if [[ $COMP_CWORD -ge |
|
|
57 | if [[ $COMP_CWORD -ge 3 ]]; then | |
|
58 | 58 | # 'history trim' and 'history clear' covered by next line |
|
59 | 59 | _ipython_get_flags history\ "${COMP_WORDS[2]}" |
|
60 | 60 | else |
|
61 | 61 | _ipython_get_flags $mode |
|
62 | 62 | |
|
63 | 63 | fi |
|
64 | 64 | opts=$"${opts}" |
|
65 | 65 | ;; |
|
66 | 66 | *) |
|
67 | 67 | opts=$baseopts |
|
68 | 68 | esac |
|
69 | 69 | # don't drop the trailing space |
|
70 | 70 | local IFS=$'\t\n' |
|
71 | 71 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
72 | 72 | return 0 |
|
73 | 73 | elif [[ $mode == "profile" ]]; then |
|
74 | 74 | opts="list create locate " |
|
75 | 75 | local IFS=$'\t\n' |
|
76 | 76 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
77 | 77 | elif [[ $mode == "history" ]]; then |
|
78 | 78 | if [[ $COMP_CWORD -ge 3 ]]; then |
|
79 | 79 | # drop into flags |
|
80 | 80 | opts="--" |
|
81 | 81 | else |
|
82 | 82 | opts="trim clear " |
|
83 | 83 | fi |
|
84 | 84 | local IFS=$'\t\n' |
|
85 | 85 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
86 | 86 | elif [[ $mode == "locate" ]]; then |
|
87 | 87 | opts="profile" |
|
88 | 88 | COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
|
89 | 89 | elif [[ ${prev} == "--pylab"* ]] || [[ ${prev} == "--gui"* ]]; then |
|
90 | 90 | if [ -z "$__ipython_complete_pylab" ]; then |
|
91 | 91 | __ipython_complete_pylab=`cat <<EOF | python - |
|
92 | 92 | try: |
|
93 | 93 | import IPython.core.shellapp as mod; |
|
94 | 94 | for k in mod.InteractiveShellApp.pylab.values: |
|
95 | 95 | print "%s " % k |
|
96 | 96 | except: |
|
97 | 97 | pass |
|
98 | 98 | EOF |
|
99 | 99 | ` |
|
100 | 100 | fi |
|
101 | 101 | local IFS=$'\t\n' |
|
102 | 102 | COMPREPLY=( $(compgen -W "${__ipython_complete_pylab}" -- ${cur}) ) |
|
103 | 103 | elif [[ ${prev} == "--profile"* ]]; then |
|
104 | 104 | if [ -z "$__ipython_complete_profiles" ]; then |
|
105 | 105 | __ipython_complete_profiles=`cat <<EOF | python - |
|
106 | 106 | try: |
|
107 | 107 | import IPython.core.profileapp |
|
108 | 108 | for k in IPython.core.profileapp.list_bundled_profiles(): |
|
109 | 109 | print "%s " % k |
|
110 | 110 | p = IPython.core.profileapp.ProfileList() |
|
111 | 111 | for k in IPython.core.profileapp.list_profiles_in(p.ipython_dir): |
|
112 | 112 | print "%s " % k |
|
113 | 113 | except: |
|
114 | 114 | pass |
|
115 | 115 | EOF |
|
116 | 116 | ` |
|
117 | 117 | fi |
|
118 | 118 | local IFS=$'\t\n' |
|
119 | 119 | COMPREPLY=( $(compgen -W "${__ipython_complete_profiles}" -- ${cur}) ) |
|
120 | 120 | else |
|
121 | 121 | if [ "$COMP_CWORD" == 1 ]; then |
|
122 | 122 | local IFS=$'\t\n' |
|
123 | 123 | local sub=$(echo $subcommands | sed -e "s/ / \t/g") |
|
124 | 124 | COMPREPLY=( $(compgen -W "${sub}" -- ${cur}) ) |
|
125 | 125 | else |
|
126 | 126 | COMPREPLY=( $(compgen -f -- ${cur}) ) |
|
127 | 127 | fi |
|
128 | 128 | fi |
|
129 | 129 | |
|
130 | 130 | } |
|
131 | 131 | complete -o default -o nospace -F _ipython ipython |
General Comments 0
You need to be logged in to leave comments.
Login now