Skip to content

Instantly share code, notes, and snippets.

@shelan
Forked from suya55/ij.sh
Created February 25, 2016 20:37
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 shelan/13fb817dcc8bf681cbc4 to your computer and use it in GitHub Desktop.
Save shelan/13fb817dcc8bf681cbc4 to your computer and use it in GitHub Desktop.
Open a project in IntelliJ IDEA from your command line! Raw
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# Setup your working directory. Edit 'work' to your working directory.
working_dir=`ls -1d ~/work/$1 | head -n1`
# 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"
# find argument in woring directory
elif [ -d $working_dir ]; then
open -a "$IDEA" $working_dir
# 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