Instantly share code, notes, and snippets.

@agoncal agoncal/idea
Created Feb 27, 2017

Embed
What would you like to do?
#!/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
@madorb

This comment has been minimized.

Copy link

madorb commented Jan 30, 2018

You might want to consider updating this now that intellij installs under the Toolbox (e.g. ~/Applications/JetBrains\ Toolbox/IntelliJ\ IDEA\ Ultimate.app)

@dotCipher

This comment has been minimized.

Copy link

dotCipher commented Jul 26, 2018

Whipped up a more dynamic version, which handles both toolbox and non-toolbox installed intellij apps, check it out here:
https://gist.github.com/dotCipher/9c5f7647bda088fde5dc561cc121b0a5

@davidlanouette

This comment has been minimized.

Copy link

davidlanouette commented Aug 2, 2018

Idea can create a similar script for you. From in Idea,

Tools > Create Command-line Launcher...

@uythoang

This comment has been minimized.

Copy link

uythoang commented Jan 8, 2019

@davidlanouette Thanks!

@ohade

This comment has been minimized.

Copy link

ohade commented Jan 15, 2019

@davidlanouette, this is why you might consider using this script instead:
https://emmanuelbernard.com/blog/2017/02/27/start-intellij-idea-command-line/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment