# mtx completion -*- shell-script -*- # by Jon Middleton proc _mtx { var cur = '', prev = '', words = '', cword = '' _init_completion || return var options = '', tapes = '', drives = '' set options = '"-f nobarcode invert noattach --version inquiry noattach \ inventory status load unload eepos first last next'" set tapes = $[mtx status !2 >/dev/null | \ awk '/Storage Element [0-9]+:Full/ { printf "%s ", $3 }] set tapes = $(tapes//:Full) set drives = $[mtx status !2 >/dev/null | \ awk '/Data Transfer Element [0-9]+:(Full|Empty)/ { printf "%s ", $4 }] set drives = $(drives//:Full) set drives = $(drives//:Empty) if [[ $cword -gt 1 ]] { match $prev { with load setglobal COMPREPLY = '( '$( compgen -W "$tapes" -- "$cur" ) ) with unload|first|last|next setglobal COMPREPLY = '( '$( compgen -W "$drives" -- "$cur" ) ) with -f true with * true } } else { setglobal COMPREPLY = '( '$( compgen -W "$options" -- "$cur" ) ) } return 0 } && complete -F _mtx mtx # ex: ts=4 sw=4 et filetype=sh