~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/bash_completion/bashcomp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-06-02 00:25:52 UTC
  • mfrom: (5255.4.4 bash_completion-TagNames)
  • Revision ID: pqm@pqm.ubuntu.com-20100602002552-r3uvzo8k1ma0kjb4
(lifeless) Tab-complete tags with names or at the edge of a revision range.
 Includes bzr-bash-completion 1.2.0. (Martin von Gagern)

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
{
67
67
        local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
68
68
        local curOpt optEnums
 
69
        local IFS=$' \\n'
69
70
 
70
71
        COMPREPLY=()
71
72
        cur=${COMP_WORDS[COMP_CWORD]}
72
73
 
73
74
        cmds='%(cmds)s'
74
 
        globalOpts='%(global_options)s'
 
75
        globalOpts=( %(global_options)s )
75
76
 
76
77
        # do ordinary expansion if we are anywhere after a -- argument
77
78
        for ((i = 1; i < COMP_CWORD; ++i)); do
89
90
 
90
91
        # complete command name if we are not already past the command
91
92
        if [[ $COMP_CWORD -le cmdIdx ]]; then
92
 
                COMPREPLY=( $( compgen -W "$cmds $globalOpts" -- $cur ) )
 
93
                COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
93
94
                return 0
94
95
        fi
95
96
 
107
108
                fi
108
109
        fi
109
110
%(debug)s
110
 
        cmdOpts=
111
 
        optEnums=
112
 
        fixedWords=
 
111
        cmdOpts=( )
 
112
        optEnums=( )
 
113
        fixedWords=( )
113
114
        case $cmd in
114
115
%(cases)s\
115
116
        *)
116
 
                cmdOpts='--help -h'
 
117
                cmdOpts=(--help -h)
117
118
                ;;
118
119
        esac
119
120
 
120
 
        if [[ -z $fixedWords ]] && [[ -z $optEnums ]] && [[ $cur != -* ]]; then
 
121
        IFS=$'\\n'
 
122
        if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
121
123
                case $curOpt in
122
 
                        tag:*)
123
 
                                fixedWords="$(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//')"
124
 
                                ;;
125
 
                esac
126
 
        elif [[ $cur == = ]] && [[ -n $optEnums ]]; then
 
124
                        tag:|*..tag:)
 
125
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
 
126
                                ;;
 
127
                esac
 
128
                case $cur in
 
129
                        [\\"\\']tag:*)
 
130
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
 
131
                                ;;
 
132
                        [\\"\\']*..tag:*)
 
133
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//') )
 
134
                                fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
 
135
                                ;;
 
136
                esac
 
137
        elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
127
138
                # complete directly after "--option=", list all enum values
128
 
                COMPREPLY=( $optEnums )
 
139
                COMPREPLY=( "${optEnums[@]}" )
129
140
                return 0
130
141
        else
131
 
                fixedWords="$cmdOpts $globalOpts $optEnums $fixedWords"
 
142
                fixedWords=( "${cmdOpts[@]}"
 
143
                             "${globalOpts[@]}"
 
144
                             "${optEnums[@]}"
 
145
                             "${fixedWords[@]}" )
132
146
        fi
133
147
 
134
 
        if [[ -n $fixedWords ]]; then
135
 
                COMPREPLY=( $( compgen -W "$fixedWords" -- $cur ) )
 
148
        if [[ ${#fixedWords[@]} -gt 0 ]]; then
 
149
                COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
136
150
        fi
137
151
 
138
152
        return 0
144
158
            "global_options": self.global_options(),
145
159
            "debug": self.debug_output(),
146
160
        })
 
161
        # Help Emacs terminate strings: "
147
162
 
148
163
    def command_names(self):
149
164
        return " ".join(self.data.all_command_aliases())
196
211
            if option.registry_keys:
197
212
                for key in option.registry_keys:
198
213
                    options.append("%s=%s" % (option, key))
199
 
                enums.append("%s) optEnums='%s' ;;" %
 
214
                enums.append("%s) optEnums=( %s ) ;;" %
200
215
                             (option, ' '.join(option.registry_keys)))
201
216
            else:
202
217
                options.append(str(option))
203
 
        case += "\t\tcmdOpts='%s'\n" % " ".join(options)
 
218
        case += "\t\tcmdOpts=( %s )\n" % " ".join(options)
204
219
        if command.fixed_words:
205
220
            fixed_words = command.fixed_words
206
221
            if isinstance(fixed_words, list):
207
 
                fixed_words = "'%s'" + ' '.join(fixed_words)
 
222
                fixed_words = "( %s )" + ' '.join(fixed_words)
208
223
            case += "\t\tfixedWords=%s\n" % fixed_words
209
224
        if enums:
210
225
            case += "\t\tcase $curOpt in\n\t\t\t"
241
256
 
242
257
    def __init__(self, name, version=None):
243
258
        if version is None:
244
 
            version = bzrlib.plugin.plugins()[name].__version__
 
259
            try:
 
260
                version = bzrlib.plugin.plugins()[name].__version__
 
261
            except:
 
262
                version = 'unknown'
245
263
        self.name = name
246
264
        self.version = version
247
265
 
335
353
            cmd_data.options.extend(self.option(opt))
336
354
 
337
355
        if 'help' == name or 'help' in cmd.aliases:
338
 
            cmd_data.fixed_words = ('"$cmds %s"' %
 
356
            cmd_data.fixed_words = ('($cmds %s)' %
339
357
                " ".join(sorted(help_topics.topic_registry.keys())))
340
358
 
341
359
        return cmd_data