# mtx completion -*- shell-script -*- # by Jon Middleton proc _mtx { local cur prev words cword _init_completion || return local options tapes drives setglobal options = '"-f nobarcode invert noattach --version inquiry noattach \ inventory status load unload eepos first last next'" setglobal tapes = $[mtx status !2 >/dev/null | \ awk '/Storage Element [0-9]+:Full/ { printf "%s ", $3 }] setglobal tapes = $(tapes//:Full) setglobal drives = $[mtx status !2 >/dev/null | \ awk '/Data Transfer Element [0-9]+:(Full|Empty)/ { printf "%s ", $4 }] setglobal drives = $(drives//:Full) setglobal 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