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