Last active
December 7, 2021 15:24
-
-
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
This file contains hidden or 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
#!/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" | |
} |
I have issues on bash-completion 2 with this functions. Them can be fixed by adding shopt -u nullglob
after line 57
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
Fixed some issues when filenames have spaces in them