Last active
October 27, 2021 21:21
-
-
Save schwa/96edd16f9bbb49f0ec9ffff80ae0d856 to your computer and use it in GitHub Desktop.
Example script showing how to use dialog (`brew install dialog`) to drive xcode-select
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 xcode-select-dialog | |
# Get current Xcode | |
set CURRENT_XCODE (xcode-select -p | sed "s/\/Contents\/Developer//") | |
# Find all Xcodes on system | |
set XCODES (mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode' && kMDItemContentType == 'com.apple.application-bundle'") | |
# Build a dialog menu | |
set MENU | |
for XCODE in $XCODES | |
set -a MENU "$XCODE" | |
if test $CURRENT_XCODE = $XCODE | |
set -a MENU "(Current)" | |
else | |
set -a MENU "" | |
end | |
end | |
# Let the user pick an xcode and bail on cancel | |
dialog --menu "Xcode" 0 0 (count $XCODES) $MENU 2>| read XCODE | |
if test -z $XCODE | |
return -1 | |
end | |
# Build a command to select an xcode | |
set COMMAND sudo xcode-select -s "$XCODE" | |
# Echo it | |
set_color bryellow; echo $COMMAND; set_color normal | |
$COMMAND | |
echo -n "Current Xcode: "; set_color brgreen; xcode-select -p | sed "s/\/Contents\/Developer//"; set_color normal | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment