Skip to content

Instantly share code, notes, and snippets.

@3lvis
Forked from shaps80/dev-scripts.sh
Created March 23, 2014 07:33
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 3lvis/9719935 to your computer and use it in GitHub Desktop.
Save 3lvis/9719935 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function openWorkspaceOrProjectWithApp()
{
if [[ -z "$1" || "$#" -ne 2 ]]; then
echo -e "Nothing found\n"
return
fi
IDEFileName=${2##*/}
filename=${1##*/}
echo -e "\nOpening $filename with $IDEFileName\n"
# open "$1" -a "$2"
}
function selectWorkspaceOrProject()
{
count=$#
file=""
if [[ $count -eq 1 ]]; then
file=$1
elif [[ $count > 1 ]]; then
echo ""
for (( i = 0; i < $count; i++ )); do
index=`expr $i + 1`
eval "filename=\${$index}"
echo -e "\t" "[$index]" "$filename"
done
printf "\nSelect the file to open: "
read -s -n 1 result
if [[ ! -z $result ]]; then
eval "file=\${$result}"
fi
fi
}
function openWorkspaceOrProject()
{
shopt -s nullglob
workspaces=(*.xcworkspace)
count=${#workspaces[@]}
if [[ count -ne 0 ]]; then
selectWorkspaceOrProject "${workspaces[@]}"
openWorkspaceOrProjectWithApp "$file" $1
else
shopt -s nullglob
projects=(*.xcodeproj)
count=${#projects[@]}
selectWorkspaceOrProject "${projects[@]}"
openWorkspaceOrProjectWithApp "$file" $1
fi
}
function opena
{
IDEPath="/Applications/AppCode.app"
openWorkspaceOrProject "$IDEPath"
}
function openx
{
IDEPath="/Applications/Xcode.app"
openWorkspaceOrProject "$IDEPath"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment