├── README.markdown ├── android └── repo /README.markdown: -------------------------------------------------------------------------------- 1 | This is a Bash completion script for the `android`, `adb`, `emulator`, `fastboot` and `repo` 2 | command-line tools from the Google Android SDK. If you'd like to add 3 | completions for other Android tools, please let me know. 4 | 5 | Install 6 | ======= 7 | 8 | 1. Install bash-completion. On many Linux distributions it is installed and 9 | enabled by default. If you don't have it already, you can probably find it 10 | in your package repository (e.g. "aptitude install bash-completion"). Mac 11 | OS X users can find it in Fink or MacPorts. 12 | 13 | 2. Copy the "android" file from this directory into the /etc/bash_completion.d 14 | folder (under "/sw/etc" or "/opt/local/etc" on Mac OS X). 15 | 16 | 3. Restart your shell. 17 | 18 | Note: If you can't install the bash-completion package, you can still use the 19 | android completion script just by sourcing it from your bashrc or profile. 20 | 21 | Author 22 | ====== 23 | 24 | Matt Brubeck . 25 | 26 | License 27 | ======= 28 | 29 | MIT license: 30 | 31 | Copyright © 2009 Matt Brubeck 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | THE SOFTWARE. 50 | -------------------------------------------------------------------------------- /android: -------------------------------------------------------------------------------- 1 | ## Bash completion for the Android SDK tools. 2 | ## 3 | ## Copyright (c) 2009 Matt Brubeck 4 | ## 5 | ## Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ## of this software and associated documentation files (the "Software"), to deal 7 | ## in the Software without restriction, including without limitation the rights 8 | ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ## copies of the Software, and to permit persons to whom the Software is 10 | ## furnished to do so, subject to the following conditions: 11 | ## 12 | ## The above copyright notice and this permission notice shall be included in 13 | ## all copies or substantial portions of the Software. 14 | ## 15 | ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ## THE SOFTWARE. 22 | 23 | function _android() 24 | { 25 | local cur prev opts cmds type types c subcommand 26 | COMPREPLY=() 27 | cur="${COMP_WORDS[COMP_CWORD]}" 28 | prev="${COMP_WORDS[COMP_CWORD-1]}" 29 | opts="--help --silent --verbose" 30 | cmds="list create move delete update" 31 | types="avd target project lib-project test-project sdk" 32 | subcommand="" 33 | type="" 34 | 35 | # Look for the subcommand. 36 | c=1 37 | while [ $c -lt $COMP_CWORD ]; do 38 | word="${COMP_WORDS[c]}" 39 | for cmd in $cmds; do 40 | if [ "$cmd" = "$word" ]; then 41 | subcommand="$word" 42 | fi 43 | done 44 | for w in $types; do 45 | if [ "$w" = "$word" ]; then 46 | type="$word" 47 | fi 48 | done 49 | c=$((++c)) 50 | done 51 | 52 | case "$subcommand $type" in 53 | " ") 54 | case "$cur" in 55 | -*) 56 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 57 | ;; 58 | esac 59 | COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) ) 60 | ;; 61 | "list ") 62 | COMPREPLY=( $(compgen -W "avd target sdk" -- ${cur}) ) 63 | ;; 64 | "create "|"update ") 65 | COMPREPLY=( $(compgen -W "avd project test-project lib-project" -- ${cur}) ) 66 | ;; 67 | "move "|"delete ") 68 | COMPREPLY=( $(compgen -W "avd" -- ${cur}) ) 69 | ;; 70 | esac 71 | 72 | case "$cur" in 73 | -*) 74 | case "$subcommand $type" in 75 | "delete ") 76 | COMPREPLY=( $(compgen -W "avd" -- ${cur}) ) 77 | ;; 78 | "create avd") 79 | COMPREPLY=( $(compgen -W "--target --sdcard --path --name --force --skin --snapshot --abi" -- ${cur}) ) 80 | ;; 81 | "move avd") 82 | COMPREPLY=( $(compgen -W "--path --name --rename" -- ${cur}) ) 83 | ;; 84 | "delete avd"|"update avd") 85 | COMPREPLY=( $(compgen -W "--name" -- ${cur}) ) 86 | ;; 87 | "create project") 88 | COMPREPLY=( $(compgen -W "--package --name --activity --target --path" -- ${cur}) ) 89 | ;; 90 | "create lib-project") 91 | COMPREPLY=( $(compgen -W "--package --name --target --path" -- ${cur}) ) 92 | ;; 93 | "create test-project") 94 | COMPREPLY=( $(compgen -W "--main --name --path" -- ${cur}) ) 95 | ;; 96 | "update project") 97 | COMPREPLY=( $(compgen -W "--target --path --name --library --subprojects" -- ${cur}) ) 98 | ;; 99 | "update lib-project") 100 | COMPREPLY=( $(compgen -W "--target --path" -- ${cur}) ) 101 | ;; 102 | "update test-project") 103 | COMPREPLY=( $(compgen -W "--main --path" -- ${cur}) ) 104 | ;; 105 | esac 106 | ;; 107 | esac 108 | return 0 109 | } 110 | complete -o default -F _android android 111 | 112 | function _adb() 113 | { 114 | local cur prev opts cmds c subcommand device_selected 115 | COMPREPLY=() 116 | cur="${COMP_WORDS[COMP_CWORD]}" 117 | prev="${COMP_WORDS[COMP_CWORD-1]}" 118 | opts="-d -e -s -p" 119 | cmds="devices push pull sync shell emu logcat forward jdwp install sideload \ 120 | uninstall bugreport help version wait-for-device start-server \ 121 | reboot reboot-bootloader \ 122 | connect disconnect \ 123 | kill-server get-state get-serialno status-window remount root ppp backup restore" 124 | cmds_not_need_device="devices help version start-server kill-server connect disconnect" 125 | subcommand="" 126 | device_selected="" 127 | 128 | # Look for the subcommand. 129 | c=1 130 | while [ $c -lt $COMP_CWORD ]; do 131 | word="${COMP_WORDS[c]}" 132 | if [ "$word" = "-d" -o "$word" = "-e" -o "$word" = "-s" ]; then 133 | device_selected=true 134 | opts="-p" 135 | fi 136 | for cmd in $cmds; do 137 | if [ "$cmd" = "$word" ]; then 138 | subcommand="$word" 139 | fi 140 | done 141 | c=$((++c)) 142 | done 143 | 144 | case "${subcommand}" in 145 | '') 146 | case "${prev}" in 147 | -p) 148 | return 0; 149 | ;; 150 | -s) 151 | # Use 'adb devices' to list serial numbers. 152 | COMPREPLY=( $(compgen -W "$(adb devices | 153 | awk '/(device|recovery|sideload)$/{print $1}')" -- ${cur} ) ) 154 | return 0 155 | ;; 156 | esac 157 | case "${cur}" in 158 | -*) 159 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 160 | return 0 161 | ;; 162 | esac 163 | if [ -z "$device_selected" ]; then 164 | local num_devices=$(( $(adb devices 2>/dev/null|wc -l) - 2 )) 165 | if [ "$num_devices" -gt "1" ]; then 166 | # With multiple devices, you must choose a device first. 167 | COMPREPLY=( $(compgen -W "${opts} ${cmds_not_need_device}" -- ${cur}) ) 168 | return 0 169 | fi 170 | fi 171 | COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) ) 172 | return 0 173 | ;; 174 | disconnect) 175 | # Use 'adb devices' to list serial numbers. 176 | COMPREPLY=( $(compgen -W "$(adb devices | 177 | awk '/(device|recovery|sideload|offline|unauthorized)$/{print $1}')" -- ${cur} ) ) 178 | return 0 179 | ;; 180 | install) 181 | case "${cur}" in 182 | -*) 183 | COMPREPLY=( $(compgen -W "-l -r -s" -- ${cur}) ) 184 | return 0 185 | ;; 186 | esac 187 | ;; 188 | forward) 189 | # Filename or installation option. 190 | COMPREPLY=( $(compgen -W "tcp: localabstract: localreserved: localfilesystem: dev: jdwp:" -- ${cur}) ) 191 | return 0 192 | ;; 193 | uninstall) 194 | case "${cur}" in 195 | -*) 196 | COMPREPLY=( $(compgen -W "-k" -- ${cur}) ) 197 | return 0 198 | ;; 199 | esac 200 | ;; 201 | logcat) 202 | case "${cur}" in 203 | -*) 204 | COMPREPLY=( $(compgen -W "-v -b -c -d -f -g -n -r -s" -- ${cur}) ) 205 | return 0 206 | ;; 207 | esac 208 | case "${prev}" in 209 | -v) 210 | COMPREPLY=( $(compgen -W "brief process tag thread raw time long" -- ${cur}) ) 211 | return 0 212 | ;; 213 | -b) 214 | COMPREPLY=( $(compgen -W "radio events main" -- ${cur}) ) 215 | return 0 216 | ;; 217 | esac 218 | ;; 219 | backup) 220 | case "${cur}" in 221 | -*) 222 | COMPREPLY=( $(compgen -W "-f -apk -noapk -obb -noobb -shared -noshared -all -system -nosystem" -- ${cur}) ) 223 | return 0 224 | ;; 225 | esac 226 | ;; 227 | esac 228 | } 229 | complete -o default -F _adb adb 230 | 231 | function _fastboot() 232 | { 233 | local cur prev opts cmds c subcommand device_selected 234 | COMPREPLY=() 235 | cur="${COMP_WORDS[COMP_CWORD]}" 236 | prev="${COMP_WORDS[COMP_CWORD-1]}" 237 | opts="-w -s -p -c -i -b -n" 238 | cmds="update flashall flash erase getvar boot devices \ 239 | reboot reboot-bootloader oem continue" 240 | subcommand="" 241 | partition_list="boot recovery system userdata bootloader radio" 242 | device_selected="" 243 | 244 | # Look for the subcommand. 245 | c=1 246 | while [ $c -lt $COMP_CWORD ]; do 247 | word="${COMP_WORDS[c]}" 248 | if [ "$word" = "-s" ]; then 249 | device_selected=true 250 | fi 251 | for cmd in $cmds; do 252 | if [ "$cmd" = "$word" ]; then 253 | subcommand="$word" 254 | fi 255 | done 256 | c=$((++c)) 257 | done 258 | 259 | case "${subcommand}" in 260 | '') 261 | case "${prev}" in 262 | -s) 263 | # Use 'fastboot devices' to list serial numbers. 264 | COMPREPLY=( $(compgen -W "$(fastboot devices|cut -f1)" -- ${cur} ) ) 265 | return 0 266 | ;; 267 | esac 268 | case "${cur}" in 269 | -*) 270 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 271 | return 0 272 | ;; 273 | esac 274 | if [ -z "$device_selected" ]; then 275 | local num_devices=$(( $(fastboot devices 2>/dev/null|wc -l) )) 276 | if [ "$num_devices" -gt "1" ]; then 277 | # With multiple devices, you must choose a device first. 278 | COMPREPLY=( $(compgen -W "-s" -- ${cur}) ) 279 | return 0 280 | fi 281 | fi 282 | COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) ) 283 | return 0 284 | ;; 285 | flash) 286 | # partition name 287 | COMPREPLY=( $(compgen -W "${partition_list}" -- ${cur}) ) 288 | return 0 289 | ;; 290 | erase) 291 | # partition name 292 | COMPREPLY=( $(compgen -W "${partition_list}" -- ${cur}) ) 293 | return 0 294 | ;; 295 | esac 296 | } 297 | complete -o default -F _fastboot fastboot 298 | 299 | function _emulator() 300 | { 301 | local cur prev opts 302 | COMPREPLY=() 303 | cur="${COMP_WORDS[COMP_CWORD]}" 304 | prev="${COMP_WORDS[COMP_CWORD-1]}" 305 | opts="-system -datadir -kernel -ramdisk -init-data -data -partition-size -cache \ 306 | -no-cache -sdcard -wipe-data -avd -skindir -skin -no-skin -memory -netspeed -netdelay \ 307 | -netfast -trace -show-kernel -shell -no-jni -logcat -no-audio -audio \ 308 | -audio-in -audio-out -raw-keys -radio -port -ports -onion -onion-alpha \ 309 | -onion-rotation -scale -dpi-device -http-proxy -timezone -dns-server \ 310 | -cpu-delay -no-boot-anim -no-window -version -report-console -gps -keyset \ 311 | -shell-serial -old-system -tcpdump -bootchart -nand-limits -qemu -verbose -debug -help \ 312 | -help-disk-images -help-keys -help-debug-tags -help-char-devices \ 313 | -help-environment -help-keyset-file -help-virtual-device -help-sdk-images \ 314 | -help-build-images -help-all" 315 | 316 | case "$prev" in 317 | -avd) 318 | COMPREPLY=( $(compgen -W "$(find ~/.android/avd -maxdepth 1 -name '*.ini' -exec basename {} .ini \;)" -- ${cur}) ) 319 | return 0 320 | ;; 321 | esac 322 | 323 | 324 | case "$cur" in 325 | @*) 326 | COMPREPLY=( $(compgen -P @ -W "$(find ~/.android/avd -maxdepth 1 -name '*.ini' -exec basename {} .ini \;)" -- ${cur:1} ) ) 327 | return 0 328 | ;; 329 | esac 330 | 331 | case "$cur" in 332 | -*) 333 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 334 | return 0 335 | ;; 336 | esac 337 | } 338 | complete -o default -F _emulator emulator 339 | -------------------------------------------------------------------------------- /repo: -------------------------------------------------------------------------------- 1 | # -*- mode: sh; -*- 2 | 3 | declare -A CMD_HANDLERS 4 | CMD_HANDLERS=( 5 | ["init"]=_repo_init 6 | ["help"]=_repo_help 7 | ["abandon"]=_repo_abandon 8 | ["branch"]=_repo_branch 9 | ["branches"]=_repo_branches 10 | ["checkout"]=_repo_checkout 11 | ["cherry-pick"]=_repo_cherry_pick 12 | ["diff"]=_repo_diff 13 | ["download"]=_repo_download 14 | ["forall"]=_repo_forall 15 | ["grep"]=_repo_grep 16 | ["list"]=_repo_list 17 | ["prune"]=_repo_prune 18 | ["rebase"]=_repo_rebase 19 | ["selfupdate"]=_repo_selfupdate 20 | ["smartsync"]=_repo_smartsync 21 | ["stage"]=_repo_stage 22 | ["start"]=_repo_start 23 | ["status"]=_repo_status 24 | ["sync"]=_repo_sync 25 | ["upload"]=_repo_upload 26 | ["version"]=_repo_version 27 | ) 28 | 29 | # To be populated by command handlers. 30 | declare -a OPTIONS 31 | declare -A ARG_OPTIONS 32 | 33 | declare cur 34 | declare prev 35 | 36 | _init_cur_prev() { 37 | cur=$(_get_cword "=") 38 | prev=$(_get_cword "=" 1) 39 | 40 | _split_longopt 41 | } 42 | 43 | _find_repo() { 44 | local dir=$(pwd) 45 | local found=1 46 | 47 | while [ "${dir}" != / ] 48 | do 49 | if [ -e "${dir}/.repo/repo/main.py" ] 50 | then 51 | found=0 52 | break 53 | fi 54 | 55 | dir=$(cd "${dir}/.." && pwd) 56 | done 57 | 58 | if [ ${found} -eq 0 ] 59 | then 60 | echo "${dir}" 61 | fi 62 | } 63 | 64 | _is_repo_dir() { 65 | local repo_root=$(_find_repo) 66 | 67 | [ -n "${repo_root}" ] 68 | } 69 | 70 | _gen_comps() { 71 | local completions="$1" 72 | local suffix="${2:- }" 73 | 74 | local -i i 75 | local -a tmp=( $(compgen -W "${completions}" -- ${cur}) ) 76 | 77 | for (( i=0; i < ${#tmp[*]}; i++ )) 78 | do 79 | tmp[$i]="${tmp[$i]}${suffix}" 80 | done 81 | 82 | COMPREPLY=( 83 | "${COMPREPLY[@]}" 84 | "${tmp[@]}" 85 | ) 86 | } 87 | 88 | _strip_colors () { 89 | # taken from http://goo.gl/7KlLZ 90 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" 91 | } 92 | 93 | _no_completion() { 94 | true 95 | } 96 | 97 | _command_completion() { 98 | local cmds 99 | 100 | if _is_repo_dir 101 | then 102 | cmds=("abandon" "branch" "branches" "checkout" "cherry-pick" "diff" 103 | "download" "forall" "grep" "help" "init" "list" "prune" "rebase" 104 | "selfupdate" "smartsync" "stage" "start" "status" "sync" 105 | "upload" "version") 106 | else 107 | cmds=("help" "init") 108 | fi 109 | 110 | _gen_comps "${cmds[*]}" 111 | } 112 | 113 | _branch_completion() { 114 | local raw_branches 115 | 116 | # separate statement required to be able to access exit code 117 | raw_branches=$(repo branches 2>/dev/null) 118 | 119 | if [ $? -eq 0 ] 120 | then 121 | local branches=$( 122 | echo "${raw_branches}" | 123 | _strip_colors | awk 'BEGIN { FS="|" } { print $1 }' | cut -c 3- 124 | ) 125 | 126 | _gen_comps "${branches}" 127 | fi 128 | } 129 | 130 | _dir_completion() { 131 | _filedir -d 132 | } 133 | 134 | _project_completion() { 135 | local repo_root=$(_find_repo) 136 | 137 | if [ -n "${repo_root}" -a -f "${repo_root}/.repo/project.list" ] 138 | then 139 | local projects=$(cat "${repo_root}/.repo/project.list") 140 | _gen_comps "${projects}" 141 | fi 142 | } 143 | 144 | _manifest_completion() { 145 | local repo_root=$(_find_repo) 146 | 147 | if [ -n "${repo_root}" ] 148 | then 149 | local manifests_dir="${repo_root}/.repo/manifests" 150 | local git_dir="${manifests_dir}/.git" 151 | local candidates 152 | 153 | manifests=$( 154 | git --git-dir "${git_dir}" ls-files "*.xml" 2>/dev/null) 155 | 156 | if [ $? -eq 0 ] 157 | then 158 | _gen_comps "${manifests}" 159 | fi 160 | fi 161 | } 162 | 163 | _path_cmd_completion() { 164 | _gen_comps "$(compgen -c ${cur})" 165 | } 166 | 167 | _is_option() { 168 | local opt="$1" 169 | 170 | [[ "${opt}" == -* ]] 171 | } 172 | 173 | _is_long_option() { 174 | local opt="$1" 175 | 176 | [[ "${opt}" == --* ]] 177 | } 178 | 179 | _expects_arg() { 180 | local opt="$1" 181 | 182 | if [[ ${ARG_OPTIONS[$opt]} ]] 183 | then 184 | return 0 185 | else 186 | return 1 187 | fi 188 | } 189 | 190 | _handle_options() { 191 | if _expects_arg "${prev}" 192 | then 193 | local handler=${ARG_OPTIONS[$prev]} 194 | eval ${handler} "${cur}" 195 | elif _is_option "${cur}" 196 | then 197 | _gen_comps "${OPTIONS[*]}" 198 | 199 | local arg_short 200 | local arg_long 201 | 202 | for opt in "${!ARG_OPTIONS[@]}" 203 | do 204 | if _is_long_option "${opt}" 205 | then 206 | arg_long="${arg_long} ${opt}" 207 | else 208 | arg_short="${arg_short} ${opt}" 209 | fi 210 | done 211 | 212 | _gen_comps "${arg_short}" 213 | _gen_comps "${arg_long}" "=" 214 | else 215 | return 1 216 | fi 217 | 218 | return 0 219 | } 220 | 221 | _is_known_shortopt() { 222 | local needle="$1" 223 | 224 | for opt in ${OPTIONS[@]} 225 | do 226 | if [ "${opt}" = "${needle}" ] 227 | then 228 | return 0 229 | fi 230 | done 231 | 232 | return 1 233 | } 234 | 235 | _is_known_longopt() { 236 | local needle="$1" 237 | 238 | [[ ${ARG_OPTIONS[$1]} ]] 239 | } 240 | 241 | _arg_index() { 242 | local -i i=2 # skip repo and command 243 | local -i ix=0 244 | 245 | while [ ${i} -lt ${COMP_CWORD} ] 246 | do 247 | if _is_known_shortopt "${COMP_WORDS[i]}" 248 | then 249 | i+=1 250 | elif _is_known_longopt "${COMP_WORDS[i]}" 251 | then 252 | i+=2 253 | elif _is_option "${COMP_WORDS[i]}" 254 | then 255 | i+=1 256 | else 257 | i+=1 258 | ix+=1 259 | fi 260 | done 261 | 262 | eval $1="${ix}" 263 | } 264 | 265 | _when_ix() { 266 | local ix="$1" 267 | local completion="$2" 268 | 269 | _arg_index arg_ix 270 | 271 | if [ ${arg_ix} -eq ${ix} ] 272 | then 273 | ${completion} 274 | return 0 275 | else 276 | return 1 277 | fi 278 | } 279 | 280 | _when_first() { 281 | _when_ix 0 "$1" 282 | } 283 | 284 | _when_even() { 285 | local completion="$1" 286 | 287 | _arg_index arg_ix 288 | 289 | if [ $(( ${arg_ix} % 2 )) -eq 0 ] 290 | then 291 | ${completion} 292 | return 0 293 | else 294 | return 1 295 | fi 296 | } 297 | 298 | _cmp_opts() { 299 | local opt="$1" 300 | local word="$2" 301 | 302 | if _is_option "${opt}" && ! _is_long_option "${opt}" 303 | then 304 | [ "${word}" == "${opt}" ] 305 | else 306 | [[ "${word}" == "${opt}"=* || "${word}" == "${opt}" ]] 307 | fi 308 | } 309 | 310 | _before() { 311 | local completion="$1" 312 | local words 313 | 314 | shift 315 | 316 | _get_comp_words_by_ref -n = words 317 | 318 | for word in "${words[@]}" 319 | do 320 | for needle in "$@" 321 | do 322 | if _cmp_opts "${needle}" "${word}" 323 | then 324 | return 1 325 | fi 326 | done 327 | done 328 | 329 | ${completion} 330 | return 0 331 | } 332 | 333 | _repo_init() { 334 | OPTIONS=( 335 | "-h" "--help" 336 | "-q" "--quite" 337 | "--mirror" 338 | "--no-repo-verify" 339 | ) 340 | 341 | ARG_OPTIONS=( 342 | ["-u"]=_no_completion 343 | ["--manifest-url"]=_no_completion 344 | ["-b"]=_no_completion 345 | ["--manifest-branch"]=_no_completion 346 | ["-m"]=_manifest_completion 347 | ["--manifest-name"]=_manifest_completion 348 | ["--reference"]=_dir_completion 349 | ["--repo-url"]=_no_completion 350 | ["--repo-branch"]=_no_completion 351 | ) 352 | 353 | _handle_options 354 | } 355 | 356 | _repo_help() { 357 | OPTIONS=( 358 | "-a" "--all" 359 | "-h" "--help" 360 | ) 361 | 362 | ARG_OPTIONS=() 363 | 364 | _handle_options || _when_first _command_completion 365 | } 366 | 367 | _repo_abandon() { 368 | OPTIONS=( 369 | "-h" "--help" 370 | ) 371 | 372 | ARG_OPTIONS=() 373 | 374 | _handle_options || _when_first _branch_completion || _project_completion 375 | } 376 | 377 | _repo_branch() { 378 | OPTIONS=( 379 | "-h" "--help" 380 | ) 381 | 382 | ARG_OPTIONS=() 383 | 384 | _handle_options 385 | } 386 | 387 | _repo_branches() { 388 | OPTIONS=( 389 | "-h" "--help" 390 | ) 391 | 392 | ARG_OPTIONS=() 393 | 394 | _handle_options 395 | } 396 | 397 | _repo_checkout() { 398 | OPTIONS=( 399 | "-h" "--help" 400 | ) 401 | 402 | ARG_OPTIONS=() 403 | 404 | _handle_options || _when_first _branch_completion || _project_completion 405 | } 406 | 407 | _repo_cherry_pick() { 408 | OPTIONS=( 409 | "-h" "--help" 410 | ) 411 | 412 | ARG_OPTIONS=() 413 | 414 | _handle_options 415 | } 416 | 417 | _repo_diff() { 418 | OPTIONS=( 419 | "-h" "--help" 420 | ) 421 | 422 | ARG_OPTIONS=() 423 | 424 | _handle_options || _project_completion 425 | } 426 | 427 | _repo_download() { 428 | OPTIONS=( 429 | "-h" "--help" 430 | ) 431 | 432 | ARG_OPTIONS=() 433 | 434 | _handle_options || _when_even _project_completion 435 | } 436 | 437 | _repo_forall() { 438 | OPTIONS=( 439 | "-h" "--help" 440 | "-p" 441 | "-v" "--verbose" 442 | ) 443 | 444 | ARG_OPTIONS=( 445 | ["-c"]=_path_cmd_completion 446 | ["--command"]=_path_cmd_completion 447 | ) 448 | 449 | _handle_options || _before _project_completion -c --command || _filedir 450 | } 451 | 452 | _repo_grep() { 453 | OPTIONS=( 454 | "-h" "--help" 455 | "--cached" 456 | "-r" "--revision" 457 | "-i" "--ignore-case" 458 | "-a" "--text" 459 | "-I" 460 | "-w" "--word-regexp" 461 | "-v" "--invert-match" 462 | "-G" "--basic-regexp" 463 | "-E" "--extended-regexp" 464 | "-F" "--fixed-strings" 465 | "--all-match" 466 | "--and" "--or" "--not" 467 | "-(" "-)" 468 | "-n" 469 | "-l" "--name-only" "--files-with-matches" 470 | "-L" "--files-without-match" 471 | ) 472 | 473 | ARG_OPTIONS=( 474 | ["-e"]=_no_completion 475 | ["-C"]=_no_completion 476 | ["-B"]=_no_completion 477 | ["-A"]=_no_completion 478 | ) 479 | 480 | _handle_options || _project_completion 481 | } 482 | 483 | _repo_list() { 484 | OPTIONS=( 485 | "-h" "--help" 486 | ) 487 | 488 | ARG_OPTIONS=() 489 | 490 | _handle_options || _project_completion 491 | } 492 | 493 | _repo_prune() { 494 | OPTIONS=( 495 | "-h" "--help" 496 | ) 497 | 498 | ARG_OPTIONS=() 499 | 500 | _handle_options || _project_completion 501 | } 502 | 503 | _repo_rebase() { 504 | OPTIONS=( 505 | "-h" "--help" 506 | "-i" "--interactive" 507 | "-f" "--force-rebase" 508 | "--no-ff" 509 | "-q" "--quiet" 510 | "--autosquash" 511 | ) 512 | 513 | ARG_OPTIONS=( 514 | ["--whitespace"]=_no_completion 515 | ) 516 | 517 | _handle_options || _project_completion 518 | } 519 | 520 | _repo_selfupdate() { 521 | OPTIONS=( 522 | "-h" "--help" 523 | "--no-repo-verify" 524 | ) 525 | 526 | ARG_OPTIONS=() 527 | 528 | _handle_options 529 | } 530 | 531 | _repo_smartsync() { 532 | OPTIONS=( 533 | "-h" "--help" 534 | "-f" "--force-broken" 535 | "-l" "--local-only" 536 | "-n" "--network-only" 537 | "-d" "--detach" 538 | "-q" "--quiet" 539 | "--no-repo-verify" 540 | ) 541 | 542 | ARG_OPTIONS=( 543 | ["-j"]=_no_completion 544 | ["--jobs"]=_no_completion 545 | 546 | ) 547 | 548 | _handle_options || _project_completion 549 | } 550 | 551 | _repo_stage() { 552 | OPTIONS=( 553 | "-h" "--help" 554 | "-i" "--interactive" 555 | ) 556 | 557 | ARG_OPTIONS=() 558 | 559 | _handle_options || _project_completion 560 | } 561 | 562 | _repo_start() { 563 | OPTIONS=( 564 | "-h" "--help" 565 | "--all" 566 | ) 567 | 568 | ARG_OPTIONS=() 569 | 570 | _handle_options || _when_first _branch_completion || _project_completion 571 | } 572 | 573 | _repo_status() { 574 | OPTIONS=( 575 | "-h" "--help" 576 | ) 577 | 578 | ARG_OPTIONS=( 579 | ["-j"]=_no_completion 580 | ["--jobs"]=_no_completion 581 | ) 582 | 583 | _handle_options || _project_completion 584 | } 585 | 586 | _repo_sync() { 587 | OPTIONS=( 588 | "-h" "--help" 589 | "-f" "--force-broken" 590 | "-l" "--local-only" 591 | "-n" "--network-only" 592 | "-d" "--detach" 593 | "-q" "--quiet" 594 | "-s" "--smart-sync" 595 | "--no-tags" 596 | "--no-repo-verify" 597 | ) 598 | 599 | ARG_OPTIONS=( 600 | ["-j"]=_no_completion 601 | ["--jobs"]=_no_completion 602 | ) 603 | 604 | _handle_options || _project_completion 605 | } 606 | 607 | _repo_upload() { 608 | OPTIONS=( 609 | "-h" "--help" 610 | "-t" 611 | "--no-verify" 612 | "--verify" 613 | ) 614 | 615 | ARG_OPTIONS=( 616 | ["--re"]=_no_completion 617 | ["--reviewers"]=_no_completion 618 | ["--cc"]=_no_completion 619 | ["--br"]=_branch_completion 620 | ) 621 | 622 | _handle_options || _project_completion 623 | } 624 | 625 | _repo_version() { 626 | OPTIONS=( 627 | "-h" "--help" 628 | ) 629 | 630 | ARG_OPTIONS=() 631 | 632 | _handle_options 633 | } 634 | 635 | _repo() { 636 | COMPREPLY=() 637 | 638 | _init_cur_prev 639 | 640 | if [ ${COMP_CWORD} -eq 1 ] 641 | then 642 | _command_completion 643 | else 644 | local cmd=${COMP_WORDS[1]} 645 | local handler=${CMD_HANDLERS["${cmd}"]} 646 | if [ -n ${handler} ] 647 | then 648 | eval ${handler} 649 | fi 650 | fi 651 | 652 | return 0 653 | } 654 | complete -o nospace -F _repo repo 655 | --------------------------------------------------------------------------------