OLD | NEW |
| (Empty) |
1 #compdef trial conch mktap cftp tapconvert twistd ckeygen lore pyhtmlizer tap2de
b tkconch manhole tap2rpm | |
2 | |
3 # Copyright (c) 2005 Eric Mangold | |
4 # See LICENSE for details. | |
5 # | |
6 # Maintainer: Eric Mangold <teratorn@twistedmatrix.com> | |
7 | |
8 # This file is meant to be in your zsh function path. i.e. in one of those | |
9 # directories listed in your $fpath variable. | |
10 # | |
11 # e.g. /usr/local/share/zsh/site-functions/ | |
12 # | |
13 # It is responsible for passing completion control to the correct | |
14 # completion function for the version of Twisted that is | |
15 # currently in use. | |
16 # | |
17 # Goals: | |
18 # | |
19 # We want to detect any changes to PYTHONPATH since the last time we ran. | |
20 # That way we can re-locate the completion functions so that we are sure | |
21 # to be completing for the right version of twisted. | |
22 | |
23 local dir old_fpath python_code run shebang | |
24 | |
25 function debug () { | |
26 echo $@ >> /tmp/debug | |
27 } | |
28 | |
29 #debug "START _twisted_stub" | |
30 | |
31 function load_twisted_completions() { | |
32 [[ -z $commands[twistd] ]] && echo 'ERROR: test command "twistd" not found i
n path' && return 1 | |
33 shebang=$(head -1 $commands[twistd]) | |
34 [[ $shebang != \#\!* ]] && echo 'ERROR: invalid shebang line for test script
"twistd"' && return 1 | |
35 PYTHON=$shebang[3,-1] | |
36 PYTHON=${PYTHON# *} | |
37 | |
38 #debug PYTHON -$PYTHON- | |
39 python_code=' | |
40 import twisted, os.path | |
41 dir = os.path.dirname(twisted.__file__) | |
42 print dir + os.sep + os.path.join("python", "zsh") | |
43 ' | |
44 dir=$($PYTHON -c "$python_code") | |
45 #debug "Trying to load twisted functions from $dir" | |
46 if [[ -r $dir/_twistd ]]; then | |
47 old_fpath=($fpath) | |
48 fpath=( $dir $fpath ) | |
49 autoload +X _trial _conch _mktap _cftp _tapconvert _twistd _ckeygen | |
50 autoload +X _lore _pyhtmlizer _tap2deb _tkconch | |
51 autoload +X _manhole _tap2rpm | |
52 fpath=($old_fpath) | |
53 else | |
54 echo 'ERROR: Cannot find twisted completion function files in:' | |
55 echo "$dir" | |
56 return 1 | |
57 fi | |
58 } | |
59 | |
60 function twisted_run () { | |
61 # run completion function for current command | |
62 # the :t modifier strips off any leading pathname components | |
63 eval _$words[1]:t | |
64 } | |
65 | |
66 function twisted_save_load_run () { | |
67 # save PYTHONPATH, load twisted completions, and run the completion | |
68 # function for the current command | |
69 load_twisted_completions && twisted_run && PYTHONPATH_last=$PYTHONPATH | |
70 } | |
71 | |
72 | |
73 if [[ -n $PYTHONPATH_last ]]; then | |
74 #debug "PYTHONPATH_last is set to $PYTHONPATH_last" | |
75 #check if it's the same as the last time we ran | |
76 if [[ $PYTHONPATH == $PYTHONPATH_last ]]; then | |
77 #debug "PYTHONPATH == PYTHONPATH_last" | |
78 # it's the same, which means we've already loaded completion | |
79 # functions and nothing has changed. | |
80 twisted_run | |
81 else | |
82 twisted_save_load_run | |
83 fi | |
84 else | |
85 twisted_save_load_run | |
86 fi | |
87 | |
88 #debug "END _twisted_stub" | |
89 # | |
OLD | NEW |