about summary refs log tree commit diff
path: root/Completion/Unix/Command/_mtools
blob: 63851b86fc1fdb324a3fc5552ebe2d926bb77fce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#compdef mattrib mcopy mdel mdu mcd mdeltree mdir mformat mlabel mmd mmount mmove mrd mread mren mtoolstest mtype

(( $+functions[_mtools_drives] )) ||
_mtools_drives() {
  local expl

  _wanted drives expl drive compadd "$@" -M "m:{a-z}={A-Z}" \
      ${${(M)${(f)"$(mtoolstest)"}:#drive*}##drive }
}

(( $+functions[_mtools_dosfiles] )) ||
_mtools_dosfiles() {
  local expl files dirs disp dirsonly suf='/' ret=1
  
  zparseopts -D -E '/=dirsonly'
  if compset -P '[A-Za-z]:'; then
    _tags files
  else
    _tags files drives
  fi
  compset -P '*/'
  if compset -S '/*'; then
    suf=''
    dirsonly=(1)
  fi

  while _tags; do
    _requested drives expl drive _mtools_drives -S '' && ret=0
    if _requested files; then
      files=( ${(f)"$(mdir -aX $IPREFIX 2>/dev/null)"} )
      dirs=( ${${${(M)files:#*/}%/}##*/} )
      disp=( $dirs/ )
      while _next_label files expl 'file'; do
	(( ! $#dirsonly )) && compadd "$@" "$expl[@]" -M 'm:{a-zA-Z}={A-Za-z}' \
	    ${files##*/} && ret=0
	compadd "$@" "$expl[@]" -M 'm:{a-zA-Z}={A-Za-z}' -S "$suf" -q \
            -d disp -a dirs && ret=0
      done
    fi
    (( ret )) || return 0
  done
  
  return ret
}

(( $+functions[_mtools_files] )) ||
_mtools_files() {
  local dos
  
  if [[ -prefix [a-zA-Z]: ]]; then
    dos='files:file:_mtools_dosfiles'
  else
    dos='drives:drive:_mtools_drives -S ""'
  fi
  _alternative $dos 'files:file:_files'
}

_mtools() {
  local args Dopt oopt sopt topt vopt

  Dopt='(-V)-D[specify name clash handling]:clash option:
    _values "name clash handling"
      "o[overwrite primary names]"
      "O[overwrite secondary names]"
      "r[rename primary name]"
      "R[rename secondary name]"
      "a[autorename primary name]"
      "A[autorename secondary name]"
      "s[skip primary name]"
      "S[skip secondary name]"
      "m[ask user what to do with primary name]"
      "M[ask user what to do with secondary name]"'
  oopt='(-V)-o[no confirmation on overwrite of DOS files]'
  sopt=( '(-V -s -/)'-{s,/}'[recurse subdirectories]' )
  topt='(-V)-t[perform text file translation]'
  vopt='(-V)-v[verbose]'

  case $service in
    mattrib)
      args=( $mdfiles
	'(-V)-+a[archive]'
	'(-V)-+h[hidden]'
	'(-V)-+r[readonly]'
	'(-V)-+s[system]'
	'(-V)-/[recurse subdirectories]'
	'(-V)-X[concise output]'
	'(-V)-p[replay mode]'  
        '(-V)*:file:_mtools_dosfiles'
      )
    ;;
    mcopy|mread)
      args=( $Dopt $oopt $sopt $topt $vopt
	'(-V)-b[batch mode]'
	'(-V)-p[preserve file attributes]' 
	'(-V)-Q[quit on failure]'
	'(-V)-a[text mode transfer]'
	'(-V)-n[no confirmation on overwrite of Unix files]'
	'(-V)-m[preserve modification time]'
	'(-V)*:source file:_mtools_files'
      )
    ;;
    mdeltree|mrd)
      args=( $vopt '(-V)*:directory:_mtools_dosfiles -/' )
    ;;
    mdel)
      args=( $vopt '(-V)*:file:_mtools_dosfiles' )
    ;;
    mdir)
      args=( $Dopt $sopt
	'(-V)-w[wide output]'
	'(-V)-a[also list hidden files]'
	'(-V)-f[fast - do not find free space]'
	'(-V -b -X)'-{b,X}'[concise output]'
	'(-V)*:file:_mtools_dosfiles'
      )
    ;;
    mdu)
      args=(
	'(-V)-a[output for all files]'
	'(-V)-s[summarize - output only for each argument]'
	'(-V)*:file:_mtools_dosfiles'
      )
    ;;
    mlabel)
      args=(
	'(-V -s)-c[clear existing label]'
	'(-V -c)-s[show existing label]'
	'(-V -N)-n[assign new random serial number]'
	'(-V -n)-N[specify new serial number]:serial number'
	'1:drive:_mtools_drives -S ""'
      )
    ;;
    mmd)
      args=( $Dopt '(-V)*:directory:_mtools_dosfiles -/' )
    ;;
    mmove|mren)
      # target file should be completed relative to source here
      args=( $Dopt $oopt $vopt '(-V)*:file:_mtools_dosfiles' )
    ;;
    mtype)
      args=( $topt
	'(-V)-s[strip the high bit]'
	'(-V)*:file:_mtools_files'
      )
    ;;
    mbadblocks|mmount|mformat|mtoolstest|mdrive)
      args=( '(-V)1:drive:_mtools_drives' )
    ;;
    mcd) args=( '(-V)*:directory:_mtools_dosfiles -/' ) ;;
  esac

  _arguments -s -S "$args[@]" \
    '(-D -o -s -t -v -w -a -h -r -s -/ -X -p -f -b * 1)-V[display version information]'
}

_mtools "$@"