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