Skip to content

Instantly share code, notes, and snippets.

@gtklocker
Created June 22, 2016 14:13
Show Gist options
  • Save gtklocker/45fb5bc26d7f88ec982ac1464ebed380 to your computer and use it in GitHub Desktop.
Save gtklocker/45fb5bc26d7f88ec982ac1464ebed380 to your computer and use it in GitHub Desktop.
#!/bin/bash
OLD_CASK_PATH="/opt/homebrew-cask/Caskroom"
NEW_CASK_PATH="/usr/local/Caskroom"
APP_DIRS=( "$HOME/Applications" "/Applications" )
mkdir -p $NEW_CASK_PATH
chown -R `whoami`:staff $NEW_CASK_PATH
for app_dir in "${APP_DIRS[@]}"; do
for app in $app_dir/*.app; do
linked_dir="`readlink "$app"`"
if [[ -d "$linked_dir" && "$linked_dir" =~ "$OLD_CASK_PATH" ]]; then
naked_path="${linked_dir#$OLD_CASK_PATH/}"
app_name="${naked_path%%/*}"
new_path="$NEW_CASK_PATH/$naked_path"
echo "Moving $app_name..."
mv "$OLD_CASK_PATH/$app_name" "$NEW_CASK_PATH/$app_name"
echo "Relinking $app_name..."
ln -sf "$new_path" "$app"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment