164 lines
4.6 KiB
Plaintext
Raw Normal View History

2009-09-14 21:48:25 +02:00
# bash completion for mdadm
2009-10-20 00:12:49 +03:00
have mdadm &&
{
2009-09-14 21:48:25 +02:00
_mdadm_raid_level()
{
2009-10-04 19:42:50 +02:00
local mode
for (( i=1; i < COMP_CWORD; i++ )); do
case ${COMP_WORDS[i]} in
-@(C|-create))
mode=create
break
;;
-@(B|-build))
mode=build
break
;;
esac
done
case $mode in
create)
COMPREPLY=( $( compgen -W 'linear raid0 0 stripe raid1 1 mirror \
raid4 4 raid5 5 raid6 6 raid10 10 multipath mp faulty' \
-- "$cur" ) )
;;
build)
COMPREPLY=( $( compgen -W 'linear stripe raid0 0 raid1 multipath \
mp faulty' -- "$cur" ) )
;;
esac
2009-09-14 21:48:25 +02:00
}
_mdadm_raid_layout()
2009-09-14 21:48:25 +02:00
{
2009-10-04 19:42:50 +02:00
local level
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" == -@(l|-level) ]]; then
level=${COMP_WORDS[i+1]}
break
fi
done
case $level in
raid5)
COMPREPLY=( $( compgen -W 'left-asymmetric left-symmetric \
right-asymmetric right-symmetric la ra ls rs' -- "$cur" ) )
;;
raid10)
COMPREPLY=( $( compgen -W 'n o p' -- "$cur" ) )
;;
faulty)
COMPREPLY=( $( compgen -W 'write-transient wt read-transient rt \
write-persistent wp read-persistent rp write-all read-fixable \
rf clear flush none' -- $cur ) )
;;
esac
2009-09-14 21:48:25 +02:00
}
_mdadm_auto_flag()
{
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( compgen -W 'no yes md mdp part p' -- "$cur" ) )
2009-09-14 21:48:25 +02:00
}
_mdadm_update_flag()
{
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( compgen -W 'sparc2.2 summaries uuid name homehost resync \
byteorder super-minor' -- "$cur" ) )
2009-09-14 21:48:25 +02:00
}
_mdadm()
{
2009-10-20 00:12:49 +03:00
local cur prev mode options split=false
2009-10-04 19:42:50 +02:00
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
2009-10-20 00:12:49 +03:00
_split_longopt && split=true
2009-10-04 19:42:50 +02:00
case $prev in
2009-10-20 00:12:49 +03:00
-c|--config|-b|--bitmap|--backup-file)
2009-10-04 19:42:50 +02:00
_filedir
return 0
;;
2009-10-20 00:12:49 +03:00
-l|--level)
2009-10-04 19:42:50 +02:00
_mdadm_raid_level
return 0
;;
2009-10-20 00:12:49 +03:00
-p|--layout|--parity)
2009-10-04 19:42:50 +02:00
_mdadm_raid_layout
return 0
;;
2009-10-20 00:12:49 +03:00
-a|--auto)
2009-10-04 19:42:50 +02:00
_mdadm_auto_flag
return 0
;;
2009-10-20 00:12:49 +03:00
-U|--update)
2009-10-04 19:42:50 +02:00
_mdadm_update_flag
return 0
;;
esac
2009-10-20 00:12:49 +03:00
$split && return 0
2009-10-04 19:42:50 +02:00
options='--help --help-options --version --verbose --quiet \
2009-10-20 00:12:49 +03:00
--brief --force --config --scan --metadata --homehost'
2009-10-04 19:42:50 +02:00
if [[ "$cur" == -* ]]; then
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$options --assemble --build \
--create --monitor --grow" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
else
case ${COMP_WORDS[COMP_CWORD-1]} in
-@(A|-assemble))
2009-10-20 00:12:49 +03:00
COMPREPLY=( $( compgen -W "$options --uuid \
--super-minor --name --force --run \
--no-degraded --auto --bitmap --backup-file \
--update --auto-update-homehost" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
;;
-@(B|C|G|-build|-create|-grow))
2009-10-20 00:12:49 +03:00
COMPREPLY=( $( compgen -W "$options --raid-devices \
--spare-devices --size --chunk --rounding \
--level --layout --parity --bitmap \
--bitmap-chunk --write-mostly --write-behind \
--assume-clean --backup-file --name --run \
--force --auto" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
;;
-@(F|-follow|-monitor))
COMPREPLY=( $( compgen -W "$options --mail --program \
--alert --syslog --delay --daemonise \
--pid-file --oneshot --test" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
;;
@(/dev/*|--add|--fail|--remove))
COMPREPLY=( $( compgen -W "$options --add --re-add \
--remove --fail --set-faulty" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
;;
*)
COMPREPLY=( $( compgen -W "$options --query --detail \
--examine --sparc2.2 --examine-bitmap --run \
--stop --readonly --readwrite \
--zero-superblock --test" -- "$cur" ) )
2009-10-04 19:42:50 +02:00
;;
esac
fi
else
cur=${cur:=/dev/}
_filedir
fi
2009-09-14 21:48:25 +02:00
}
complete -F _mdadm mdadm
}
# Local variables:
# mode: shell-script
2009-10-04 19:42:50 +02:00
# sh-basic-offset: 4
# sh-indent-comment: t
2009-10-04 19:42:50 +02:00
# indent-tabs-mode: nil
# End:
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh