Imported Upstream version 1.3.12
[debian/mtx] / debian / bash_completion
1 # mtx completion by Jon Middleton <jjm@ixtab.org.uk>
2 #
3 # $Id: bash_completion,v 1.1 2004-02-15 05:43:25 bdale Exp $
4
5 _mtx()
6 {
7     local cur prev options tapes drives
8     
9     COMPREPLY=()
10     cur=${COMP_WORDS[COMP_CWORD]}
11     prev=${COMP_WORDS[COMP_CWORD-1]}
12
13     options="-f nobarcode invert noattach --version inquiry noattach \
14              inventory status load unload eepos first last next"
15
16     tapes=$(mtx status | \
17         awk '/Storage Element [0-9]+:Full/ { printf "%s ", $3 }')
18     tapes=${tapes//:Full}
19
20     drives=$(mtx status | \
21              awk '/Data Transfer Element [0-9]+:(Full|Empty)/ { printf "%s ", $4 }')
22     drives=${drives//:Full}
23     drives=${drives//:Empty}
24
25     if [ $COMP_CWORD -gt 1 ]; then
26         case $prev in 
27             load) 
28                 COMPREPLY=( $( compgen -W "$tapes" -- $cur ) )          
29                 ;;
30             unload|first|last|next)
31                 COMPREPLY=( $( compgen -W "$drives" -- $cur ) )
32                 ;;
33             -f)
34                 true
35                 ;;
36             *)
37                 true
38                 ;;
39         esac
40     else
41         COMPREPLY=( $( compgen -W "$options" -- $cur ) )
42     fi
43     return 0
44
45 complete -F _mtx mtx