假設我們有一個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來打開項目了。
