-
Notifications
You must be signed in to change notification settings - Fork 3
/
diskutil
executable file
·278 lines (235 loc) · 5.18 KB
/
diskutil
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Bash completion for diskutil
# by Tony Williams, honestpuck@gmail.com
# version 0.3
# 23/05/2017
__du_comp_words_include() {
local i=1
while [[ "$i" -lt "$COMP_CWORD" ]]
do
if [[ "${COMP_WORDS[i]}" = "$1" ]]
then
return 0
fi
i="$((++i))"
done
return 1
}
__du_comp() {
# break $1 on space, tab, and newline characters,
# and turn it into a newline separated list of words
local list s sep=$'\n' IFS=$' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
for s in $1
do
__du_comp_words_include "$s" && continue
list="$list$s$sep"
done
IFS="$sep"
COMPREPLY=($(compgen -W "$list" -- "$cur"))
}
_du_list() {
__du_comp "-plist internal external physical virtual"
return
}
_du_info() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
__du_comp "-all -plist"
return
;;
esac
}
_du_activity() {
return
}
_du_listFilesystems() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
__du_comp "-plist"
return
;;
esac
}
_du_unmount() {
__du_comp "force"
return
}
_du_unmountDisk() {
__du_comp "force"
return
}
_du_eject() {
return
}
_du_mount() {
__du_comp "readOnly -mountPoint"
return
}
_du_mountDisk() {
return
}
_du_rename() {
return
}
_du_enableJournal() {
return
}
_du_disableJournal() {
__du_comp "force"
return
}
_du_moveJournal() {
__du_comp "external internal"
return
}
_du_enableOwnership() {
return
}
_du_disableOwnership() {
return
}
_du_verifyVolume() {
return
}
_du_repairVolume() {
return
}
_du_verifyDisk() {
return
}
_du_repairDisk() {
return
}
_du_eraseVolume() {
__du_comp "APFS ExFAT FAT16 FAT32 HFS+ hfsx jhfsx jhfs+ readOnly -mountPoint"
return
}
_du_eraseDisk() {
__du_comp "APFS ExFAT FAT16 FAT32 HFS+ hfsx jhfsx jhfs+ APM MBR GPT"
return
}
_du_reformat() {
return
}
_du_eraseOptical() {
__du_comp "quick"
return
}
_du_zeroDisk() {
__du_comp "force"
return
}
_du_randomDisk() {
return
}
_du_secureErase() {
__du_comp "freespace"
return
}
_du_partitionDisk() {
__du_comp "APFS ExFAT FAT16 FAT32 HFS+ hfsx jhfsx jhfs+ APM MBR GPT"
return
}
_du_resizeVolume() {
__du_comp "limits mapsize R APFS ExFAT FAT16 FAT32 HFS+ hfsx jhfsx jhfs+ "
return
}
_du_splitPartition() {
__du_comp "APFS ExFAT FAT16 FAT32 HFS+ hfsx jhfsx jhfs+ "
return
}
_du_mergePartitions() {
__du_comp "force"
return
}
_du_appleRAID() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
__du_comp "-plist"
return
;;
esac
__du_comp "list create mirror stripe concat delete repairMirror add remove enable update"
}
_du_APFS() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
__du_comp "-plist -fileencryption -effaceable -reserve -quota -role -nomount \
-mountpoint"
return
;;
esac
__du_comp "list create createContainer deleteContainer resizeContainer addVolume \
addVolume deleteVolume eraseVolume changeVolumeRole defragment"
}
_du_coreStorage() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*)
__du_comp "-plist -stdinpassphrase -passphrase -recoverykeychain -nomount \
-oldpassphrase -newpassphrase "
return
;;
esac
__du_comp "list info convert revert createLVG deleteLVG renameLVG createLV \
deleteLV encryptLV decryptLV unlockLV changeVolumePassphrase resizeLV \
resizeDisk resizePV resizeStack"
}
_diskutil() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ "$COMP_CWORD" = "1" ]] # we are matching the command
then
opts="list info activity listFilesystems unmount unmountDisk eject mount mountDisk \
rename enableJournal disableJournal moveJournal enableOwnership disableOwnership \
verifyVolume repairVolume verifyDisk repairDisk eraseVolume eraseDisk reformat \
eraseOptical zeroDisk randomDisk secureErase partitionDisk resizeVolume \
splitPartition mergePartitions APFS appleRAID coreStorage "
COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
return 0
fi
cmd="${COMP_WORDS[1]}"
case "$cmd" in
list) _du_list ;;
info) _du_info ;;
activity) _du_activity ;;
listFilesystems) _du_listFilesystems ;;
unmount) _du_unmount ;;
unmountDisk) _du_unmountDisk ;;
eject) _du_eject ;;
mount) _du_mount ;;
mountDisk) _du_mountDisk ;;
rename) _du_rename ;;
enableJournal) _du_enableJournal ;;
disableJournal) _du_disableJournal ;;
moveJournal) _du_moveJournal ;;
enableOwnership) _du_enableOwnership ;;
disableOwnership) _du_disableOwnership ;;
verifyVolume) _du_verifyVolume ;;
repairVolume) _du_repairVolume ;;
verifyDisk) _du_verifyDisk ;;
repairDisk) _du_repairDisk ;;
eraseVolume) _du_eraseVolume ;;
eraseDisk) _du_eraseDisk ;;
reformat) _du_reformat ;;
eraseOptical) _du_eraseOptical ;;
zeroDisk) _du_zeroDisk ;;
randomDisk) _du_randomDisk ;;
secureErase) _du_secureErase ;;
partitionDisk) _du_partitionDisk ;;
resizeVolume) _du_resizeVolume ;;
splitPartition) _du_splitPartition ;;
mergePartitions) _du_mergePartitions ;;
APFS) _du_APFS ;;
apfs) _du_APFS ;;
appleRAID) _du_appleRAID ;;
coreStorage) _du_coreStorage ;;
esac
}
complete -o bashdefault -o default -F _diskutil diskutil