Skip to content

Instantly share code, notes, and snippets.

@dral3x
Forked from shaps80/dev-scripts.sh
Last active August 28, 2018 07:55
Show Gist options
  • Save dral3x/1bbcedaa871fcd04f303 to your computer and use it in GitHub Desktop.
Save dral3x/1bbcedaa871fcd04f303 to your computer and use it in GitHub Desktop.
Open workspace or project from current directory with Xcode, AppCode or Android Studio app. Script will looks for workspaces first, than fallback to project files (when appropriate). Subdirectories are ignored.
#!/usr/bin/env bash
# Published on https://gist.github.com/dral3x/1bbcedaa871fcd04f303
## Common
function __openFileWithApp()
{
if [[ -z "$1" || "$#" -ne 2 ]]; then
echo -e "Nothing found\n"
return
fi
ide=${2##*/}
filename=${1##*/}
echo -e "Opening $filename with $ide"
open "$1" -a "$2"
}
## iOS Stuff
function __openWorkspaceOrProject()
{
wcount="$(find . -maxdepth 1 -name '*.xcworkspace' | wc -l | bc)"
if [ $wcount -eq 1 ]; then
workspaces="$(find . -maxdepth 1 -name '*.xcworkspace' -print)"
__openFileWithApp "$workspaces" $1
return
elif [ $wcount -gt 1 ]; then
echo "Unable to open workspace file. Too many workspaces in current dir."
return
fi
pcount="$(find . -maxdepth 1 -name '*.xcodeproj' | wc -l | bc)"
if [ $pcount -eq 1 ]; then
projects="$(find . -maxdepth 1 -name '*.xcodeproj' -print)"
__openFileWithApp "$projects" $1
return
elif [ $pcount -gt 1 ]; then
echo "Unable to open project file. Too many projects in current dir."
return
fi
echo "Unable to found workspace or project in current dir."
}
openX()
{
IDE_PATH="/Applications/Xcode.app"
__openWorkspaceOrProject "$IDE_PATH"
}
openXB()
{
IDE_PATH="/Applications/Xcode-beta.app"
__openWorkspaceOrProject "$IDE_PATH"
}
## Android Stuff
openAS()
{
IDE_PATH="/Applications/Android Studio.app"
__openFileWithApp . "$IDE_PATH"
}
openASB()
{
IDE_PATH="$(find /Applications -mindepth 1 -maxdepth 1 -name "Android Studio*Preview.app" -type d)"
__openFileWithApp . "$IDE_PATH"
}
wearDebugBT()
{
adb forward tcp:4444 localabstract:/adb-hub
adb connect 127.0.0.1:4444
}
adb_shot()
{
DESKTOP_PATH="$HOME/Desktop"
IMAGE_NAME="screen-$(date +"%Y%m%d-%H%M%S").png"
adb shell screencap "/sdcard/$IMAGE_NAME"
sleep 1
adb pull "/sdcard/$IMAGE_NAME" "$DESKTOP_PATH"
sleep 1
adb shell rm "/sdcard/$IMAGE_NAME"
sleep 1
open "$DESKTOP_PATH/$IMAGE_NAME"
}
adb_rec()
{
DESKTOP_PATH="$HOME/Desktop"
VIDEO_NAME="demo-$(date +"%Y%m%d-%H%M%S").mp4"
echo "Press CTRL+C to end recording"
adb shell screenrecord "/sdcard/$VIDEO_NAME"
sleep 1
adb pull "/sdcard/$VIDEO_NAME" "$DESKTOP_PATH"
sleep 1
adb shell rm "/sdcard/$VIDEO_NAME"
sleep 1
open "$DESKTOP_PATH/$VIDEO_NAME"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment