Skip to content

Instantly share code, notes, and snippets.

@AfzalivE
Forked from chrisdarroch/idea
Last active January 15, 2020 09:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfzalivE/6651fdbc21e0c87de4dd4f031b8e1102 to your computer and use it in GitHub Desktop.
Save AfzalivE/6651fdbc21e0c87de4dd4f031b8e1102 to your computer and use it in GitHub Desktop.
Open/Import a gradle or idea project in Android Studio from your command line!
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/Android\ Studio.app | tail -n1`
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" "settings.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