命令行使用Intellij Idea

  1. 新建脚本.idea.sh置于home目录下,脚本来自于https://gist.github.com/chrisdarroch/7018927,具体内容如下:
#!/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
  1. 我用的zsh,在~/.zshrc中添加一行alias idea="sh ~/.idea.sh"
  2. 命令行输入source ~/.zshrc

以上就可以在命令行中用idea命令打开你的java项目了,亲测有以下几种打开项目的方式

  1. 上级目录下输入idea $projectDir
  2. 当前项目目录输入ideaidea pom.xml

你可能感兴趣的:(命令行使用Intellij Idea)