-
-
Save chrisdarroch/7018927 to your computer and use it in GitHub Desktop.
Open a project in IntelliJ IDEA from your command line!
This file contains 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/sh | |
# check for where the latest version of IDEA is installed | |
IDEA=`ls -1d /Applications/IntelliJ\ * | 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 an IDEA project file? | |
elif [ -f *.ipr ]; then | |
# echo "opening via the project file" | |
open -a "$IDEA" `ls -1d *.ipr | head -n1` | |
# Is there a pom.xml? | |
elif [ -f pom.xml ]; then | |
# echo "importing from pom" | |
open -a "$IDEA" "pom.xml" | |
# can't do anything smart; just open IDEA | |
else | |
# echo 'cbf' | |
open "$IDEA" | |
fi | |
popd > /dev/null | |
fi |
This is great!
I improved it a bit with some logic that will dynamically pick the either intellij installation found (non-toolbox or toolbox installed) app, check it out here:
https://gist.github.com/dotCipher/9c5f7647bda088fde5dc561cc121b0a5
This function doesn't return the latest version.
183.4886.12
183.4886.3 <-- returns this one
I had to sort by modified date using ls -tr
.
I use this:
export JETBRAINS_TOOLBOX_ROOT="${HOME}/Library/Application Support/JetBrains/Toolbox/apps"
# product = IDEA-U, CLion, etc.
# bin = idea, clion, etc.
jetbrainsToolboxPath() {
product=$1
bin=$2
# -tr = sort by last update in reverse
ret=`ls -tr -1d "${JETBRAINS_TOOLBOX_ROOT}"/$product/*/*/*.app/Contents/MacOS/$bin | tail -n1`
# Escape string because it has spaces.
echo $(printf '%q' $ret)
}
export LATEST_IDEA_VERSION_CLI=`jetbrainsToolboxPath IDEA-U idea`
export LATEST_CLION_VERSION_CLI=`jetbrainsToolboxPath Clion clion`
export LATEST_APPCODE_VERSION_CLI=`jetbrainsToolboxPath AppCode appcode`
Setup
curl -L "https://gist.githubusercontent.com/chrisdarroch/7018927/raw/9a6d663fd7a52aa76a943fe8a9bc6091ad06b18d/idea" -o /usr/local/bin/idea chmod +x /usr/local/bin/idea
usage: open terminal and navigate to your project
idea .
Tested on Mac OS X
Note: If you get a “Permission denied” error, your /usr/local/bin directory probably isn’t writable and you’ll need to install script as the superuser. Run sudo -i, then the two commands above, then exit.
Thank you
thx!
Thx @cris
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to use it with Jetbrains TOOLBOX you need to modify 4th line: