# bash completion for mdadm -*- shell-script -*- proc _mdadm_raid_level { local mode for (( i=1; i < cword; i++ )); do case ${words[i]} in -C|--create) mode=create break ;; -B|--build) mode=build break ;; esac done match $mode { with create setglobal COMPREPLY = ''( $( compgen -W 'linear raid0 0 stripe raid1 1 mirror raid4 4 raid5 5 raid6 6 raid10 10 multipath mp faulty' \ -- "$cur" ) ) with build setglobal COMPREPLY = ''( $( compgen -W 'linear stripe raid0 0 raid1 multipath mp faulty' -- "$cur" ) ) } } proc _mdadm_raid_layout { local level for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == -@(l|-level) ]]; then level=${words[i+1]} break fi done match $level { with raid5 setglobal COMPREPLY = ''( $( compgen -W 'left-asymmetric left-symmetric right-asymmetric right-symmetric la ra ls rs' -- "$cur" ) ) with raid10 setglobal COMPREPLY = ''( $( compgen -W 'n o p' -- "$cur" ) ) with faulty setglobal COMPREPLY = ''( $( compgen -W 'write-transient wt read-transient rt write-persistent wp read-persistent rp write-all read-fixable rf clear flush none' -- "$cur" ) ) } } proc _mdadm_auto_flag { setglobal COMPREPLY = ''( $( compgen -W 'no yes md mdp part p' -- "$cur" ) ) } proc _mdadm_update_flag { setglobal COMPREPLY = ''( $( compgen -W 'sparc2.2 summaries uuid name homehost resync byteorder super-minor' -- "$cur" ) ) } proc _mdadm { local cur prev words cword split _init_completion -s || return match $prev { with -c|--config|-b|--bitmap|--backup-file _filedir return 0 with -l|--level _mdadm_raid_level return 0 with -p|--layout|--parity _mdadm_raid_layout return 0 with -a|--auto _mdadm_auto_flag return 0 with -U|--update _mdadm_update_flag return 0 } $split && return 0 local options='--help --help-options --version --verbose --quiet --brief --force --config= --scan --metadata= --homehost=' if [[ "$cur" == -* ]] { if [[ $cword -eq 1 ]] { setglobal COMPREPLY = ''( $( compgen -W "$options --assemble --build --create --monitor --grow" -- "$cur" ) ) } else { match $(words[cword-1]) { with -A|--assemble setglobal COMPREPLY = ''( $( compgen -W "$options --uuid= --super-minor= --name= --force --run --no-degraded --auto= --bitmap= --backup-file= --update= --auto-update-homehost" \ -- "$cur" ) ) with -B|-C|-G|--build|--create|--grow setglobal 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" ) ) with -F|--follow|--monitor setglobal COMPREPLY = ''( $( compgen -W "$options --mail --program --alert --syslog --delay --daemonise --pid-file --oneshot --test" -- "$cur" ) ) with /dev/*|--add|--fail|--remove setglobal COMPREPLY = ''( $( compgen -W "$options --add --re-add --remove --fail --set-faulty" -- "$cur" ) ) with * setglobal COMPREPLY = ''( $( compgen -W "$options --query --detail --examine --sparc2.2 --examine-bitmap --run --stop --readonly --readwrite --zero-superblock --test" \ -- "$cur" ) ) } } [[ $COMPREPLY == *= ]] && compopt -o nospace } else { setglobal cur = $(cur:=/dev/) _filedir } } && complete -F _mdadm mdadm # ex: ts=4 sw=4 et filetype=sh