Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active December 7, 2021 15:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shaps80/9652980 to your computer and use it in GitHub Desktop.
Save shaps80/9652980 to your computer and use it in GitHub Desktop.
Open Xcode and AppCode projects from the command line. I recommend keeping this in a separate file and just importing the code into your bash_profile using: source ~/.dev-scripts.sh
#!/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"
}
@shaps80
Copy link
Author

shaps80 commented Mar 20, 2014

Fixed some issues when filenames have spaces in them

@chipp
Copy link

chipp commented Jun 4, 2015

I have issues on bash-completion 2 with this functions. Them can be fixed by adding shopt -u nullglob after line 57

@alexanderjrobinson
Copy link

FYI...You can use xed . to open the workspace or project in the current directory.

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