码迷,mamicode.com
首页 > 其他好文 > 详细

从命令行打开IntelliJ IDEA及IntelliJ IDEA CE

时间:2020-12-28 11:04:55      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ons   pom   directory   one   opd   vim   tor   version   install   

假设我们有一个springboot项目,使用Maven构建的。当我们使用git clone xxx.git将项目clone到本地之后,我们怎么打开项目?
打开idea,新建empty project ,然后import from desk ? 太麻烦了。通过配置快捷命令,可以使用idea pom.xml打开项目。

在用户目录创建一个.idea.sh ,然后输入下面的一段脚本。

cd ~/
touch .idea.sh
vim .idea.sh

输入如下内容,保存退出。

#!/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

创建命令别名

vim ~/.zshrc
输入 alias idea="sh ~/.idea.sh"

刷新配置,使生效:

source  ~/.zshrc

测试命令行打开Maven项目

cd /path/to/maven_project
idea pom.xml

以上配置无误的话,此时立马就能看到idea启动了,Maven项目已打开。

如果你像我一样,电脑上安装了IDEA CE的话,可以再配置一个ideace的别名。
跟上面的步骤一样,新建一个 .ideace.sh,内容跟.idea.sh的内容一样,只需要改变一行:

IDEA=`ls -1d /Applications/IntelliJ\ IDEA\ CE* | tail -n1`

然后创建一个别名alias ideace="sh ~/.ideace.sh"

接下来,便可以使用 ideace pom.xml来打开项目了。

从命令行打开IntelliJ IDEA及IntelliJ IDEA CE

标签:ons   pom   directory   one   opd   vim   tor   version   install   

原文地址:https://www.cnblogs.com/demingblog/p/14169436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!