-
-
Save AfzalivE/3b11e967b4e6663d15e5978b739bcc75 to your computer and use it in GitHub Desktop.
Android Studio terminal launcher
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
| #!/bin/bash | |
| # check for where the latest version of IDEA is installed | |
| STUDIOS=() | |
| STUDIO_NAMES=() | |
| while read line | |
| do | |
| studio=`echo $line` | |
| STUDIOS+=("${studio}") | |
| studio_name=`echo $line | sed 's/.*\///'` | |
| studio_version=`echo $line | sed 's/\/.*ch\-\d*[^\]\/\(.*\)\/Android.*/\1/g'` | |
| STUDIO_NAMES+=("${studio_name} (${studio_version})") | |
| STUDIO_VERSIONS+=("${studio_version}") | |
| done < <(find /Users/<your-username>/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio -type d -name "*.app") | |
| # select | |
| PS3="Enter number to select Android Studio: " | |
| select studio in "${STUDIO_NAMES[@]}" | |
| do | |
| case "$studio" in | |
| *) | |
| index=$(($REPLY - 1)) | |
| IDEA=${STUDIOS[index]} | |
| # adb -s `echo $studio | awk '{print $1}'` $@ | |
| break;; | |
| esac | |
| done | |
| wd=`pwd` | |
| # were we given a directory? | |
| if [ -d "$1" ]; then | |
| echo "checking for things in the working dir given" | |
| wd=`ls -1d "$1" | head -n1` | |
| fi | |
| # were we given a file? | |
| if [ -f "$1" ]; then | |
| echo "opening '$1'" | |
| open -a "$IDEA" "$1" | |
| else | |
| # let's check for stuff in our working directory. | |
| pushd $wd > /dev/null | |
| # does our working dir have an .idea directory? | |
| if [ -d ".idea" ]; then | |
| echo "opening via the .idea dir" | |
| open -a "$IDEA" . | |
| # Is there a settings.gradle? | |
| elif [ -f settings.gradle ]; then | |
| echo "importing from gradle" | |
| # open -a "$IDEA" . | |
| open -a "$IDEA" settings.gradle | |
| # Is there a build.gradle? | |
| elif [ -f build.gradle ]; then | |
| echo "importing from gradle" | |
| # open -a "$IDEA" . | |
| open -a "$IDEA" build.gradle | |
| # can't do anything smart; just open IDEA | |
| else | |
| echo 'cbf' | |
| open "$IDEA" | |
| fi | |
| popd > /dev/null | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment