Created
October 25, 2017 09:44
-
-
Save plechev/91d8ae09cfa7674053c08b866b9e3629 to your computer and use it in GitHub Desktop.
Maven shell command aliasing (Bash)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bash | |
# | |
# Saves typing by allowing commands like `m ci` to be translated to `mvn clean install` | |
# Mapping lists can be customised for dev environment | |
# | |
declare -A mavg=(["c"]="clean" | |
["i"]="install" | |
["t"]="test" | |
["p"]="package" | |
["v"]="verify" | |
["g"]="generate-sources" | |
["r"]="versions:display-dependency-updates" | |
["a"]="dependency:analyze-only" | |
["h"]="help:effective-pom" | |
) | |
declare -A mavo=(["x"]="-X" | |
["e"]="-e" | |
) | |
declare -A mavp=( | |
["D"]="-Pdev" | |
["S"]="-Pstage" | |
["P"]="-Pprod" | |
["L"]="-Plcl" | |
) | |
declare -A mavd=( | |
["n"]="-DskipTests" | |
["N"]="-DskipITs" | |
) | |
declare -A mave=( | |
["/"]="&> /tmp/maven-build.log" | |
) | |
function m() { | |
s=$1 | |
if [ "$s" == "?" ]; then | |
echo "Goals: " | |
parray "$(declare -p mavg)" | |
echo "Options: " | |
parray "$(declare -p mavo)" | |
echo "Profiles: " | |
parray "$(declare -p mavp)" | |
echo "JVM Options: " | |
parray "$(declare -p mavd)" | |
echo "Extras: " | |
parray "$(declare -p mave)" | |
else | |
ro="" | |
mvn=("mvn"); | |
# do goals first | |
for ((i=0; i<${#s}; i++)); do | |
mvn+=(${mavg[${s:$i:1}]}); | |
done | |
# options | |
for ((i=0; i<${#s}; i++)); do | |
mvn+=(${mavo[${s:$i:1}]}); | |
done | |
# profiles | |
for ((i=0; i<${#s}; i++)); do | |
mvn+=(${mavp[${s:$i:1}]}); | |
done | |
# -D | |
for ((i=0; i<${#s}; i++)); do | |
mvn+=(${mavd[${s:$i:1}]}); | |
done | |
# extras | |
for ((i=0; i<${#s}; i++)); do | |
if [ ${s:$i:1} == ">" ]; then | |
ro=${mave[${s:$i:1}]} | |
else | |
mvn+=(${mave[${s:$i:1}]}); | |
fi | |
done | |
cmd="${mvn[@]} $ro" | |
printf '_%.0s' {1..100} | |
printf "\n\tExecuting: %s\n" "$cmd" | |
printf '=%.0s' {1..100} | |
printf "\n\n" | |
eval "$cmd" | |
fi | |
} | |
function parray { | |
eval "declare -A arg_array=${1#*=}" | |
for i in "${!arg_array[@]}"; do | |
printf " %s\t%s\n" "$i => ${arg_array[$i]}" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment