rename _get_command to _get_first_arg, and move it to main file, as it is a generic utility function
This commit is contained in:
parent
b68a572119
commit
0098435c71
@ -974,8 +974,24 @@ _realcommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This function returns the first arugment, excluding options
|
||||||
|
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
|
||||||
|
# NOT be considered word breaks. See __reassemble_comp_words_by_ref.
|
||||||
|
_get_first_arg()
|
||||||
|
{
|
||||||
|
local i
|
||||||
|
|
||||||
# This function counts the number of args
|
arg=
|
||||||
|
for (( i=1; i < COMP_CWORD; i++ )); do
|
||||||
|
if [[ "${COMP_WORDS[i]}" != -* ]]; then
|
||||||
|
arg=${COMP_WORDS[i]}
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# This function counts the number of args, excluding options
|
||||||
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
|
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
|
||||||
# NOT be considered word breaks. See __reassemble_comp_words_by_ref.
|
# NOT be considered word breaks. See __reassemble_comp_words_by_ref.
|
||||||
_count_args()
|
_count_args()
|
||||||
|
@ -28,19 +28,6 @@ _bluetooth_packet_types()
|
|||||||
-- "$cur" ) )
|
-- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
_get_command()
|
|
||||||
{
|
|
||||||
local i
|
|
||||||
|
|
||||||
command=
|
|
||||||
for (( i=1; i < COMP_CWORD; i++ )); do
|
|
||||||
if [[ "${COMP_WORDS[i]}" != -* ]]; then
|
|
||||||
command=${COMP_WORDS[i]}
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
_hcitool()
|
_hcitool()
|
||||||
{
|
{
|
||||||
local cur prev split=false
|
local cur prev split=false
|
||||||
@ -68,8 +55,8 @@ _hcitool()
|
|||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
_get_command
|
_get_first_arg
|
||||||
if [ -z $command ]; then
|
if [ -z $arg ]; then
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--help -i' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W '--help -i' -- "$cur" ) )
|
||||||
else
|
else
|
||||||
@ -78,7 +65,7 @@ _hcitool()
|
|||||||
afh lst auth enc key clkoff clock' -- "$cur" ) )
|
afh lst auth enc key clkoff clock' -- "$cur" ) )
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
case $command in
|
case $arg in
|
||||||
name|info|dc|rssi|lq|afh|auth|key|clkoff|lst)
|
name|info|dc|rssi|lq|afh|auth|key|clkoff|lst)
|
||||||
_count_args
|
_count_args
|
||||||
if [ $args -eq 2 ]; then
|
if [ $args -eq 2 ]; then
|
||||||
@ -143,8 +130,8 @@ _sdptool()
|
|||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
_get_command
|
_get_first_arg
|
||||||
if [ -z $command ]; then
|
if [ -z $arg ]; then
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
|
||||||
else
|
else
|
||||||
@ -152,7 +139,7 @@ _sdptool()
|
|||||||
del get setattr setseq' -- "$cur" ) )
|
del get setattr setseq' -- "$cur" ) )
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
case $command in
|
case $arg in
|
||||||
search)
|
search)
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--bdaddr \
|
COMPREPLY=( $( compgen -W '--bdaddr \
|
||||||
@ -230,8 +217,8 @@ _rfcomm()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
_get_command
|
_get_first_arg
|
||||||
if [ -z $command ]; then
|
if [ -z $arg ]; then
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--help -a --raw \
|
COMPREPLY=( $( compgen -W '--help -a --raw \
|
||||||
--config -i --auth --encrypt --secure --master' -- "$cur" ) )
|
--config -i --auth --encrypt --secure --master' -- "$cur" ) )
|
||||||
@ -244,7 +231,7 @@ _rfcomm()
|
|||||||
if [ $args -eq 2 ]; then
|
if [ $args -eq 2 ]; then
|
||||||
_bluetooth_devices
|
_bluetooth_devices
|
||||||
else
|
else
|
||||||
case $command in
|
case $arg in
|
||||||
connect|bind)
|
connect|bind)
|
||||||
if [ $args -eq 3 ]; then
|
if [ $args -eq 3 ]; then
|
||||||
_bluetooth_adresses
|
_bluetooth_adresses
|
||||||
@ -272,8 +259,8 @@ _ciptool()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
_get_command
|
_get_first_arg
|
||||||
if [ -z $command ]; then
|
if [ -z $arg ]; then
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--help -i' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W '--help -i' -- "$cur" ) )
|
||||||
else
|
else
|
||||||
@ -281,7 +268,7 @@ _ciptool()
|
|||||||
loopback' -- "$cur" ) )
|
loopback' -- "$cur" ) )
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
case $command in
|
case $arg in
|
||||||
connect|release|loopback)
|
connect|release|loopback)
|
||||||
_count_args
|
_count_args
|
||||||
if [ $args -eq 2 ]; then
|
if [ $args -eq 2 ]; then
|
||||||
@ -332,8 +319,8 @@ _hciconfig()
|
|||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=`_get_cword`
|
cur=`_get_cword`
|
||||||
|
|
||||||
_get_command
|
_get_first_arg
|
||||||
if [ -z $command ]; then
|
if [ -z $arg ]; then
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '--help --all' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W '--help --all' -- "$cur" ) )
|
||||||
else
|
else
|
||||||
@ -346,7 +333,7 @@ _hciconfig()
|
|||||||
-- "$cur" ) )
|
-- "$cur" ) )
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
case $command in
|
case $arg in
|
||||||
putkey|delkey)
|
putkey|delkey)
|
||||||
_count_args
|
_count_args
|
||||||
if [ $args -eq 2 ]; then
|
if [ $args -eq 2 ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user