Skip to content

Instantly share code, notes, and snippets.

@hraban
Forked from dixson3/workspace.sh
Created January 6, 2019 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hraban/84462b53f13b02c491cc22be3c5b0538 to your computer and use it in GitHub Desktop.
Save hraban/84462b53f13b02c491cc22be3c5b0538 to your computer and use it in GitHub Desktop.
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
#!/bin/bash
set -eu -o pipefail
${DEBUGSH+set -x}
# where to store the sparse-image
NAME=civol
SPARSELOC=~/Documents/$NAME.dmg
FSTYPE="APFS"
create() {
hdiutil create -type SPARSEBUNDLE -fs "$FSTYPE" -size 60g -volname "$NAME" "${SPARSELOC}"
attach
}
detach() {
m=$(hdiutil info | grep "/Volumes/$NAME" | cut -f1)
if [ ! -z "$m" ]; then
hdiutil detach $m
fi
}
attach() {
hdiutil attach "${SPARSELOC}.sparsebundle"
}
compact() {
detach
hdiutil compact "${SPARSELOC}" -batteryallowed
attach
}
case "${1-}" in
create) create;;
attach) attach;;
detach) detach;;
compact) compact;;
*)
>&2 echo "Needs an argument: create | attach | detach | compact"
exit 1 ;;
esac
# vim: set sw=4 sts=4 et :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment