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

假设我们有一个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来打开项目了。

posted @   逃离沙漠  阅读(2379)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示