Skip to content

Instantly share code, notes, and snippets.

@phdoerfler
Forked from grocky/idea
Last active November 27, 2016 17:14
Show Gist options
  • Select an option

  • Save phdoerfler/5718de7afaaef8632e5d to your computer and use it in GitHub Desktop.

Select an option

Save phdoerfler/5718de7afaaef8632e5d to your computer and use it in GitHub Desktop.

Revisions

  1. Philipp Dörfler revised this gist Dec 11, 2015. 1 changed file with 0 additions and 0 deletions.
    Empty file modified idea
    100644 → 100755
    Empty file.
  2. phdoerfler revised this gist Dec 8, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions idea
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,8 @@ function openWithDirectory() {

    open -a "$IDEA" "${PROJECT_DIR}/pom.xml"

    elif [ -f "${PROJECT_DIR}/build.sbt" ]; then
    open -a "$IDEA" "${PROJECT_DIR}/build.sbt"
    else
    open -a "$IDEA" "${PROJECT_DIR}"
    fi
  3. @grocky grocky revised this gist Jun 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion idea
    Original file line number Diff line number Diff line change
    @@ -95,4 +95,4 @@ function getWebStormApp() {
    ls -1d /Applications/WebStorm* | tail -n1
    }

    main "$@"
    main "$@"
  4. @grocky grocky revised this gist Jun 22, 2015. 1 changed file with 89 additions and 26 deletions.
    115 changes: 89 additions & 26 deletions idea
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,98 @@
    #!/usr/bin/env bash

    IDEA=$(ls -1d /Applications/IntelliJ\ * | tail -n1)
    wd=$(pwd)

    # were we given a directory?
    if [ -d "$1" ]; then
    wd=$(ls -1d "$1" | head -n1)
    fi
    IDEA=''
    PROJECT_DIR=''

    function main() {
    openIdea "$@"
    }

    function openIdea() {

    if [ -f "$1" ]; then
    openByFile
    fi

    openWithDirectory "$1"
    }

    function openByFile() {

    if [ "$1" ~= '.php' ]; then
    IDEA=$(getPhpStormApp)
    fi

    if [ "$1" ~= '.js' ] || [ "$1" ~= '.css' ]; then
    IDEA=$(getWebStormApp)
    fi

    # were we given a file?
    if [ -f "$1" ]; then
    open -a "$IDEA" "$1"
    else
    pushd $wd > /dev/null
    }

    function openWithDirectory() {

    PROJECT_DIR=$(getProjectDirectory)

    detectProjectIdeaApplication

    if [ -d "${PROJECT_DIR}/.idea" ]; then

    echo "opening via the .idea dir"
    open -a "$IDEA" ${PROJECT_DIR}

    elif [ -f "${PROJECT_DIR}/*.ipr" ]; then

    echo "opening via the project file"
    open -a "$IDEA" $(ls -1d *.ipr | head -n1)

    elif [ -f "${PROJECT_DIR}/pom.xml" ]; then

    open -a "$IDEA" "${PROJECT_DIR}/pom.xml"

    else
    open -a "$IDEA" "${PROJECT_DIR}"
    fi

    }

    function getProjectDirectory() {

    if [ -d "$1" ]; then
    ls -1d "$1" | head -n1
    fi

    if [ -z "$1" ]; then
    pwd
    fi

    }

    function detectProjectIdeaApplication() {

    if [ -f "${PROJECT_DIR}/composer.json" ]; then
    IDEA=$(getPhpStormApp)
    return 0
    fi

    if [ -f "${PROJECT_DIR}/package.json" ]; then
    IDEA=$(getWebStormApp)
    return 0
    fi

    IDEA=$(getIntelliJ)

    if [ -d ".idea" ]; then
    echo "opening via the .idea dir"
    open -a "$IDEA" .
    }

    elif [ -f *.ipr ]; then
    echo "opening via the project file"
    open -a "$IDEA" $(ls -1d *.ipr | head -n1)
    function getIntelliJ() {
    ls -1d /Applications/IntelliJ\ * | tail -n1
    }

    # Is there a pom.xml?
    elif [ -f pom.xml ]; then
    open -a "$IDEA" "pom.xml"
    function getPhpStormApp() {
    ls -1d /Applications/PhpStorm* | tail -n1
    }

    # can't do anything smart; just open IDEA
    else
    open "$IDEA"
    fi
    function getWebStormApp() {
    ls -1d /Applications/WebStorm* | tail -n1
    }

    popd > /dev/null
    fi
    main "$@"
  5. @grocky grocky revised this gist Jun 22, 2015. 1 changed file with 7 additions and 15 deletions.
    22 changes: 7 additions & 15 deletions idea
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,33 @@
    #!/bin/sh
    #!/usr/bin/env bash

    # check for where the latest version of IDEA is installed
    IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
    wd=`pwd`
    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`
    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"
    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`
    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

  6. @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