Created
June 15, 2021 17:29
-
-
Save mseijas/f0ebc94224cfa6ba73415d98e7cb6881 to your computer and use it in GitHub Desktop.
Open active Xcode version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function openxcode() { | |
if pgrep -x "Xcode" > /dev/null; then | |
read -k 1 "USER_INPUT?Xcode is already running. Close running version first? (y/N) " | |
if [[ "$USER_INPUT" =~ ^[Yy]$ ]]; then | |
killall Xcode | |
fi | |
fi | |
ACTIVE_XCODE_DIRECTORY=$(xcode-select -p) | |
SUFFIX_LENGTH=19 # "/Contents/Developer" | |
ACTIVE_XCODE_PATH=$(sed "s/.\{$SUFFIX_LENGTH\}$//" <<<"$ACTIVE_XCODE_DIRECTORY") | |
SYMLINK_PATH="/Applications/Xcode.app" | |
rm -f $SYMLINK_PATH | |
ln -sf $ACTIVE_XCODE_PATH $SYMLINK_PATH | |
open -a "$SYMLINK_PATH" "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment