mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 13:06:59 +02:00
Programmatic bash completion for Chromium OS build scripts.
If you source this script inside chroot, you would get <tab> completion for the --board= argument for some build scripts. For example, . bash_completion ./build_image --board=x<tab> may complete to ./build_image --board=x86-generic if x86-generic is the only available board starting with "x". If not, it will list available boards with the given prefix. We could extend this to work with setup_board and other scripts. Also, it may be nice to extend it to work outside chroot. Does it make sense to make this part of the regular dev chroot by default? If so, not sure what the best way to do that. Maybe install this as a hard-host-depends and source it from the chroot user .bashrc? Review URL: http://codereview.chromium.org/652129
This commit is contained in:
parent
92c9e5258d
commit
049dbab5bd
100
bash_completion
Normal file
100
bash_completion
Normal file
@ -0,0 +1,100 @@
|
||||
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Add programmable completion to some Chromium OS build scripts
|
||||
|
||||
|
||||
# Look for "--arg=foo" or "--arg foo" (where foo can be an empty string) in the
|
||||
# word to be completed. If found, echo "--arg=foo".
|
||||
#
|
||||
_argeq()
|
||||
{
|
||||
local arg=$1
|
||||
local w0="${COMP_WORDS[COMP_CWORD]}"
|
||||
local w1="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
# Check for completing "--arg="
|
||||
if [ "${w1}" == ${arg} -a "${w0}" == "=" ]; then
|
||||
echo "${w1}${w0}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check for completing "--arg foo"
|
||||
if [ "${w1}" == ${arg} ]; then
|
||||
echo "${w1}=${w0}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check for completing "--arg=foo"
|
||||
if [ ${COMP_CWORD} -gt 2 ]; then
|
||||
local w2="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
if [ "${w2}" == ${arg} -a "${w1}" == "=" ]; then
|
||||
echo "${w2}${w1}${w0}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# echo the existing target board sysroots
|
||||
#
|
||||
_board_sysroots()
|
||||
{
|
||||
local builddir=/build
|
||||
if [ ! -d ${builddir} ]; then
|
||||
echo ""
|
||||
else
|
||||
echo $(command ls "${builddir}")
|
||||
fi
|
||||
}
|
||||
|
||||
# Completion for --board= argument for existing board sysroots
|
||||
#
|
||||
_board_sysroot()
|
||||
{
|
||||
COMPREPLY=()
|
||||
local arg=$(_argeq --board)
|
||||
if [[ ${arg} == --board=* ]]; then
|
||||
COMPREPLY=( $(compgen -W "$(_board_sysroots)" -- ${arg#--board=}) )
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o bashdefault -o default -F _board_sysroot \
|
||||
build_autotest.sh \
|
||||
build_image \
|
||||
build_packages \
|
||||
image_to_usb
|
||||
|
||||
|
||||
# echo the existing target board overlays
|
||||
#
|
||||
_board_overlays()
|
||||
{
|
||||
local overlaydir=../overlays
|
||||
if [ ! -d ${overlaydir} ]; then
|
||||
echo ""
|
||||
else
|
||||
echo $(command ls $overlaydir | grep overlay- | sed s,overlay-,,)
|
||||
fi
|
||||
}
|
||||
|
||||
# Completion for --board= argument for existing board overlays
|
||||
#
|
||||
_board_overlay()
|
||||
{
|
||||
COMPREPLY=()
|
||||
local arg=$(_argeq --board)
|
||||
if [[ ${arg} == --board=* ]]; then
|
||||
COMPREPLY=( $(compgen -W "$(_board_overlays)" -- ${arg#--board=}) )
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o bashdefault -o default -F _board_overlay setup_board
|
||||
|
||||
|
||||
### Local Variables:
|
||||
### mode: shell-script
|
||||
### End:
|
Loading…
Reference in New Issue
Block a user