Skip to content

Instantly share code, notes, and snippets.

@nyteshade
Created September 4, 2024 02:15
Show Gist options
  • Save nyteshade/6ddec49e288288fde9c695ada7ebecce to your computer and use it in GitHub Desktop.
Save nyteshade/6ddec49e288288fde9c695ada7ebecce to your computer and use it in GitHub Desktop.
diskutil volume info
#!/bin/sh
function volInfo() {
# Flags for verbose output
local verbose=false
# Process optional parameters
while (( "$#" )); do
case "$1" in
--show-name | --verbose | -v | -s)
verbose=true
shift
;;
*)
break
;;
esac
done
# Store the disks to process
local disks=("$@")
# Initialize the output variable
local output=""
# Process each disk
for disk in "${disks[@]}"; do
# Capture the output of diskutil
local disk_info
disk_info=$(diskutil info "$disk")
# Extract the Volume Name
local volume_name
volume_name=$(echo "$disk_info" | grep "Volume Name:" | awk -F: '{print $2}' | xargs)
# Extract the Volume UUID
local volume_uuid
volume_uuid=$(echo "$disk_info" | grep "Volume UUID:" | awk -F: '{print $2}' | xargs)
# Append to output
if $verbose; then
output+="${volume_uuid}: ${volume_name}\n"
else
output+="${volume_uuid} "
fi
unset disk_info
unset volume_uuid
unset volume_name
done
# Print the output
if $verbose; then
printf "%b\n" "$output"
else
printf "%s" "${output% }" # Remove trailing space
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment