sped up searching for maven project properties
This commit is contained in:
parent
4be4063ec7
commit
2975bfafd4
33
.zshrc
33
.zshrc
@ -22,10 +22,18 @@ GEAR="\u2699"
|
|||||||
BULLET="\u2022"
|
BULLET="\u2022"
|
||||||
CROSSING="\u292c"
|
CROSSING="\u292c"
|
||||||
|
|
||||||
# Project in current directory
|
#--- Helpers
|
||||||
MAVEN_PROJECT_ARTIFACT=""
|
|
||||||
MAVEN_PROJECT_VERSION=""
|
|
||||||
|
|
||||||
|
find_up () {
|
||||||
|
path=$(pwd)
|
||||||
|
while [[ "$path" != "" ]]; do
|
||||||
|
if [[ -e "$path/$1" ]]; then
|
||||||
|
echo "$path/$1"
|
||||||
|
return;
|
||||||
|
fi
|
||||||
|
path=${path%/*}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
#---------------------------------- Tab completion ----------------------------
|
#---------------------------------- Tab completion ----------------------------
|
||||||
|
|
||||||
@ -398,19 +406,24 @@ mvn-color()
|
|||||||
}
|
}
|
||||||
alias mvn='mvn-color'
|
alias mvn='mvn-color'
|
||||||
|
|
||||||
MAVEN_PROJECT_ARTIFACT=""
|
# Read project into current directory
|
||||||
MAVEN_PROJECT_VERSION=""
|
|
||||||
|
|
||||||
maven_read_project() {
|
maven_read_project() {
|
||||||
local pom_contents
|
local location parts
|
||||||
if [[ ! -r "pom.xml" ]]; then
|
location=$(find_up pom.xml)
|
||||||
|
if [[ ! -r "$location" ]]; then
|
||||||
MAVEN_PROJECT_ARTIFACT=""
|
MAVEN_PROJECT_ARTIFACT=""
|
||||||
MAVEN_PROJECT_VERSION=""
|
MAVEN_PROJECT_VERSION=""
|
||||||
return 1;
|
return 1;
|
||||||
fi
|
fi
|
||||||
pom_contents=$(cat pom.xml)
|
parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \
|
||||||
MAVEN_PROJECT_ARTIFACT=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" - <<< "$pom_contents")
|
"cat /*[local-name()='project']/*[local-name()='version']/text()\n" \
|
||||||
MAVEN_PROJECT_VERSION=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='version']/text()" - <<< "$pom_contents")
|
"cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" | \
|
||||||
|
xmllint --shell $location | \
|
||||||
|
sed '/^\/ >/d' | \
|
||||||
|
sed '/^ -------/d'))
|
||||||
|
MAVEN_PROJECT_ARTIFACT=${parts[1]}
|
||||||
|
MAVEN_PROJECT_VERSION=${parts[2]}
|
||||||
}
|
}
|
||||||
|
|
||||||
add-zsh-hook chpwd maven_read_project
|
add-zsh-hook chpwd maven_read_project
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user