Skip to content

Instantly share code, notes, and snippets.

@richo
Created September 23, 2013 06:45
Show Gist options
  • Save richo/6667132 to your computer and use it in GitHub Desktop.
Save richo/6667132 to your computer and use it in GitHub Desktop.
_vm with xcode
require File.expand_path('../lib/manager', __FILE__)
class Xcode < Manager
include PosixProxy
name "xcode"
set_prefix ","
include Plugin::List
# Needs to be included last of the main_case plugins
include Plugin::Set
include Plugin::Use
include Plugin::Reset
end
_xcode = Xcode.new
_xcode.build
,xcode() {
case "$1" in
-h|--help)
echo "usage: _xcode [version] [opts]"
;;
-v|--version)
echo "_xcode version 0.0.6"
;;
system)
_xcode_reset
;;
"")
for i in ${__xcode_LIST}; do
if [ "$i" = "${xcode_ROOT}" ]
then
star='*'
else
star=' '
fi
echo " $star $(basename $i)"
done
;;
*)
for i in ${__xcode_LIST}; do
if [ "$(basename $i)" = "$1" ]
then
shift
_xcode_use "$i" "$*"
return "$?"
fi
done
echo "_xcode: unknown xcode: $1"
;;
esac
}
_xcode_use() {
if [ -n "${xcode_ROOT}" ]
then
_xcode_reset
fi
export xcode_ROOT="$1"
if [ -n "${_xcode_PATH_fragment}" ]
then
export PATH=$(echo "$PATH" | \sed -e "s|${_xcode_PATH_fragment}||" -e "s|::|:|" -e "s|^:||" -e "s|:$||")
fi
_xcode_PATH_fragment="${_xcode_PATH_fragment}:${xcode_ROOT}/bin"
export PATH="${_xcode_PATH_fragment}:${PATH}"
}
_xcode_reset() {
if [ -n "${_xcode_PATH_fragment}" ]
then
export PATH=$(echo "$PATH" | \sed -e "s|${_xcode_PATH_fragment}||" -e "s|::|:|" -e "s|^:||" -e "s|:$||")
fi
_xcode_PATH_fragment=''
if [ -n "${xcode_ROOT}" ]
then
unset xcode_ROOT
fi
}
elektra ⚡ ,xcode ~
xcode4
xcode5
elektra ⚡ which lldb ~
/usr/bin/lldb
elektra ⚡ ,xcode xcode4 ~
elektra ⚡ which lldb ~
elekt 1 ⚡ which lldb ~
/Users/richo/.xcode/xcode4/bin/lldb
elektra ⚡ ,xcode xcode5 ~
elektra ⚡ which lldb ~
/Users/richo/.xcode/xcode5/bin/lldb
elektra ⚡ ,xcode system ~
elektra ⚡ which lldb ~
/usr/bin/lldb
elektra ⚡ ~
@richo
Copy link
Author

richo commented Sep 23, 2013

Shell config is like:

__xcode_LIST=~/.xcode/*
emulate sh -c "$(ruby ~/code/ext/_vm/_xcode)"

With symlinks like:

$ ls -al .xcode
lrwxr-xr-x    1 richo  staff     46 23 Sep 16:41 xcode4 -> /Applications/Xcode.app/Contents/Developer/usr
lrwxr-xr-x    1 richo  staff     50 23 Sep 16:41 xcode5 -> /Applications/Xcode5-DP.app/Contents/Developer/usr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment