OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # Add programmable completion to some Chromium OS build scripts |
| 6 |
| 7 |
| 8 # Look for "--arg=foo" or "--arg foo" (where foo can be an empty string) in the |
| 9 # word to be completed. If found, echo "--arg=foo". |
| 10 # |
| 11 _argeq() |
| 12 { |
| 13 local arg=$1 |
| 14 local w0="${COMP_WORDS[COMP_CWORD]}" |
| 15 local w1="${COMP_WORDS[COMP_CWORD-1]}" |
| 16 |
| 17 # Check for completing "--arg=" |
| 18 if [ "${w1}" == ${arg} -a "${w0}" == "=" ]; then |
| 19 echo "${w1}${w0}" |
| 20 return 0 |
| 21 fi |
| 22 |
| 23 # Check for completing "--arg foo" |
| 24 if [ "${w1}" == ${arg} ]; then |
| 25 echo "${w1}=${w0}" |
| 26 return 0 |
| 27 fi |
| 28 |
| 29 # Check for completing "--arg=foo" |
| 30 if [ ${COMP_CWORD} -gt 2 ]; then |
| 31 local w2="${COMP_WORDS[COMP_CWORD-2]}" |
| 32 if [ "${w2}" == ${arg} -a "${w1}" == "=" ]; then |
| 33 echo "${w2}${w1}${w0}" |
| 34 return 0 |
| 35 fi |
| 36 fi |
| 37 } |
| 38 |
| 39 |
| 40 # echo the existing target board sysroots |
| 41 # |
| 42 _board_sysroots() |
| 43 { |
| 44 local builddir=/build |
| 45 if [ ! -d ${builddir} ]; then |
| 46 echo "" |
| 47 else |
| 48 echo $(command ls "${builddir}") |
| 49 fi |
| 50 } |
| 51 |
| 52 # Completion for --board= argument for existing board sysroots |
| 53 # |
| 54 _board_sysroot() |
| 55 { |
| 56 COMPREPLY=() |
| 57 local arg=$(_argeq --board) |
| 58 if [[ ${arg} == --board=* ]]; then |
| 59 COMPREPLY=( $(compgen -W "$(_board_sysroots)" -- ${arg#--board=}) ) |
| 60 return 0 |
| 61 fi |
| 62 } |
| 63 |
| 64 complete -o bashdefault -o default -F _board_sysroot \ |
| 65 build_autotest.sh \ |
| 66 build_image \ |
| 67 build_packages \ |
| 68 image_to_usb |
| 69 |
| 70 |
| 71 # echo the existing target board overlays |
| 72 # |
| 73 _board_overlays() |
| 74 { |
| 75 local overlaydir=../overlays |
| 76 if [ ! -d ${overlaydir} ]; then |
| 77 echo "" |
| 78 else |
| 79 echo $(command ls $overlaydir | grep overlay- | sed s,overlay-,,) |
| 80 fi |
| 81 } |
| 82 |
| 83 # Completion for --board= argument for existing board overlays |
| 84 # |
| 85 _board_overlay() |
| 86 { |
| 87 COMPREPLY=() |
| 88 local arg=$(_argeq --board) |
| 89 if [[ ${arg} == --board=* ]]; then |
| 90 COMPREPLY=( $(compgen -W "$(_board_overlays)" -- ${arg#--board=}) ) |
| 91 return 0 |
| 92 fi |
| 93 } |
| 94 |
| 95 complete -o bashdefault -o default -F _board_overlay setup_board |
| 96 |
| 97 |
| 98 ### Local Variables: |
| 99 ### mode: shell-script |
| 100 ### End: |
OLD | NEW |