Skip to content

Instantly share code, notes, and snippets.

@takuya
Created June 7, 2016 15:55
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save takuya/3e6964e46bebb69c3264ab45172e171f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
diskutil_options="activity
appleRAID
coreStorage
disableJournal
disableOwnership
eject
enableJournal
enableOwnership
eraseDisk
eraseOptical
eraseVolume
info
list
listFilesystems
mergePartitions
mount
mountDisk
moveJournal
partitionDisk
randomDisk
reformat
rename [Volume]
repairDisk
repairVolume
resizeVolume
secureErase
splitPartition
umount
unmount
unmountDisk
verifyDisk
verifyVolume
zeroDisk
"
# echo "$options" | awk '{print $1 }'
### 引数をecho するだけの簡単な関数。
### 補完関数。
_diskutil(){
arg0="${COMP_WORDS[0]}"
arg1="${COMP_WORDS[1]}"
list=$( echo "$diskutil_options" | awk '{print $1}')
if [ $arg1 ] ; then
for sub in $list ; do
if [ $arg1 = $sub ] ; then
list=$(diskutil list | /usr/bin/grep /dev/disk | awk '{ print $1 }')
COMPREPLY=( $(compgen -W "$list" ${COMP_WORDS[COMP_CWORD]} ) )
diskutil list
return;
fi
done
fi
COMPREPLY=( $(compgen -W "$list" ${COMP_WORDS[COMP_CWORD]} ) )
}
complete -F _diskutil diskutil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment