Skip to content

Instantly share code, notes, and snippets.

@kfuchs
Forked from chrisdarroch/idea
Created November 14, 2015 15:40
Show Gist options
  • Save kfuchs/1cccf21d9ead98604cfa to your computer and use it in GitHub Desktop.
Save kfuchs/1cccf21d9ead98604cfa to your computer and use it in GitHub Desktop.

Revisions

  1. @chrisdarroch chrisdarroch created this gist Oct 17, 2013.
    43 changes: 43 additions & 0 deletions idea
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/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