/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 19:38:57 UTC
  • mfrom: (7143.16.21 even-more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116193857-bs5oma2655sp55qu
Fix another dozen flake8 errors.

Merged from https://code.launchpad.net/~jelmer/brz/even-more-cleanups/+merge/358931

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
        return ("""\
71
71
%(function_name)s ()
72
72
{
73
 
        local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
74
 
        local curOpt optEnums
75
 
        local IFS=$' \\n'
76
 
 
77
 
        COMPREPLY=()
78
 
        cur=${COMP_WORDS[COMP_CWORD]}
79
 
 
80
 
        cmds='%(cmds)s'
81
 
        globalOpts=( %(global_options)s )
82
 
 
83
 
        # do ordinary expansion if we are anywhere after a -- argument
84
 
        for ((i = 1; i < COMP_CWORD; ++i)); do
85
 
                [[ ${COMP_WORDS[i]} == "--" ]] && return 0
86
 
        done
87
 
 
88
 
        # find the command; it's the first word not starting in -
89
 
        cmd=
90
 
        for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
91
 
                if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
92
 
                        cmd=${COMP_WORDS[cmdIdx]}
93
 
                        break
94
 
                fi
95
 
        done
96
 
 
97
 
        # complete command name if we are not already past the command
98
 
        if [[ $COMP_CWORD -le cmdIdx ]]; then
99
 
                COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
100
 
                return 0
101
 
        fi
102
 
 
103
 
        # find the option for which we want to complete a value
104
 
        curOpt=
105
 
        if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
106
 
                curOpt=${COMP_WORDS[COMP_CWORD - 1]}
107
 
                if [[ $curOpt == = ]]; then
108
 
                        curOpt=${COMP_WORDS[COMP_CWORD - 2]}
109
 
                elif [[ $cur == : ]]; then
110
 
                        cur=
111
 
                        curOpt="$curOpt:"
112
 
                elif [[ $curOpt == : ]]; then
113
 
                        curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
114
 
                fi
115
 
        fi
 
73
    local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
 
74
    local curOpt optEnums
 
75
    local IFS=$' \\n'
 
76
 
 
77
    COMPREPLY=()
 
78
    cur=${COMP_WORDS[COMP_CWORD]}
 
79
 
 
80
    cmds='%(cmds)s'
 
81
    globalOpts=( %(global_options)s )
 
82
 
 
83
    # do ordinary expansion if we are anywhere after a -- argument
 
84
    for ((i = 1; i < COMP_CWORD; ++i)); do
 
85
        [[ ${COMP_WORDS[i]} == "--" ]] && return 0
 
86
    done
 
87
 
 
88
    # find the command; it's the first word not starting in -
 
89
    cmd=
 
90
    for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
 
91
        if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
 
92
            cmd=${COMP_WORDS[cmdIdx]}
 
93
            break
 
94
        fi
 
95
    done
 
96
 
 
97
    # complete command name if we are not already past the command
 
98
    if [[ $COMP_CWORD -le cmdIdx ]]; then
 
99
        COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
 
100
        return 0
 
101
    fi
 
102
 
 
103
    # find the option for which we want to complete a value
 
104
    curOpt=
 
105
    if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
 
106
        curOpt=${COMP_WORDS[COMP_CWORD - 1]}
 
107
        if [[ $curOpt == = ]]; then
 
108
            curOpt=${COMP_WORDS[COMP_CWORD - 2]}
 
109
        elif [[ $cur == : ]]; then
 
110
            cur=
 
111
            curOpt="$curOpt:"
 
112
        elif [[ $curOpt == : ]]; then
 
113
            curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
 
114
        fi
 
115
    fi
116
116
%(debug)s
117
 
        cmdOpts=( )
118
 
        optEnums=( )
119
 
        fixedWords=( )
120
 
        case $cmd in
 
117
    cmdOpts=( )
 
118
    optEnums=( )
 
119
    fixedWords=( )
 
120
    case $cmd in
121
121
%(cases)s\
122
 
        *)
123
 
                cmdOpts=(--help -h)
124
 
                ;;
125
 
        esac
126
 
 
127
 
        IFS=$'\\n'
128
 
        if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
129
 
                case $curOpt in
130
 
                        tag:|*..tag:)
131
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
132
 
                                ;;
133
 
                esac
134
 
                case $cur in
135
 
                        [\\"\\']tag:*)
136
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
137
 
                                ;;
138
 
                        [\\"\\']*..tag:*)
139
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//') )
140
 
                                fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
141
 
                                ;;
142
 
                esac
143
 
        elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
144
 
                # complete directly after "--option=", list all enum values
145
 
                COMPREPLY=( "${optEnums[@]}" )
146
 
                return 0
147
 
        else
148
 
                fixedWords=( "${cmdOpts[@]}"
149
 
                             "${globalOpts[@]}"
150
 
                             "${optEnums[@]}"
151
 
                             "${fixedWords[@]}" )
152
 
        fi
153
 
 
154
 
        if [[ ${#fixedWords[@]} -gt 0 ]]; then
155
 
                COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
156
 
        fi
157
 
 
158
 
        return 0
 
122
    *)
 
123
        cmdOpts=(--help -h)
 
124
        ;;
 
125
    esac
 
126
 
 
127
    IFS=$'\\n'
 
128
    if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
 
129
        case $curOpt in
 
130
            tag:|*..tag:)
 
131
                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
 
132
                ;;
 
133
        esac
 
134
        case $cur in
 
135
            [\\"\\']tag:*)
 
136
                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
 
137
                ;;
 
138
            [\\"\\']*..tag:*)
 
139
                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//') )
 
140
                fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
 
141
                ;;
 
142
        esac
 
143
    elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
 
144
        # complete directly after "--option=", list all enum values
 
145
        COMPREPLY=( "${optEnums[@]}" )
 
146
        return 0
 
147
    else
 
148
        fixedWords=( "${cmdOpts[@]}"
 
149
                     "${globalOpts[@]}"
 
150
                     "${optEnums[@]}"
 
151
                     "${fixedWords[@]}" )
 
152
    fi
 
153
 
 
154
    if [[ ${#fixedWords[@]} -gt 0 ]]; then
 
155
        COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
 
156
    fi
 
157
 
 
158
    return 0
159
159
}
160
160
""" % {
161
161
            "cmds": self.command_names(),
174
174
            return ''
175
175
        else:
176
176
            return (r"""
177
 
        # Debugging code enabled using the --debug command line switch.
178
 
        # Will dump some variables to the top portion of the terminal.
179
 
        echo -ne '\e[s\e[H'
180
 
        for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
181
 
                echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
182
 
        done
183
 
        for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
184
 
                echo "\$${i}=\"${!i}\""$'\e[K'
185
 
        done
186
 
        echo -ne '---\e[K\e[u'
 
177
    # Debugging code enabled using the --debug command line switch.
 
178
    # Will dump some variables to the top portion of the terminal.
 
179
    echo -ne '\e[s\e[H'
 
180
    for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
 
181
        echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
 
182
    done
 
183
    for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
 
184
        echo "\$${i}=\"${!i}\""$'\e[K'
 
185
    done
 
186
    echo -ne '---\e[K\e[u'
187
187
""")
188
188
 
189
189
    def brz_version(self):