Skip to content

Instantly share code, notes, and snippets.

@k3vinw
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k3vinw/9520813 to your computer and use it in GitHub Desktop.
Save k3vinw/9520813 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function mvn_wrapper() {
local mvn
# integrate with custom mvn_color wrapper
if [ "$(type -t mvn_color)" == "function" ]; then
mvn=mvn_color
else
# locate mvn from user's path
mvn=$(which mvn)
fi
# capture start time in global for post comparison
export MVN_START_TIME=$SECONDS
$mvn $@
local mvn_exit=$?
local build_time=$(mvn_build_time)
local build_info=$(mvn_build_info)
test $mvn_exit == 0 && \
mvn_alert "$build_info Success after $build_time" || \
mvn_alert "$build_info FAILURE after $build_time"
return $mvn_exit
}
function mvn_build_info() {
local build_info
local project_name=$(basename $(pwd))
build_info="$project_name"
local git_branch=$(git branch 2>/dev/null |awk '/^\*/ {print $2}')
local project_branch=$(test ${PIPESTATUS[0]} == 0 && echo "$git_branch")
if [ ! -z "$project_branch" ]; then
build_info="$project_name-$project_branch"
fi
echo $build_info
}
function mvn_build_time(){
local MVN_END_TIME=$SECONDS
local seconds=0
let seconds=$MVN_END_TIME-$MVN_START_TIME
local hours=$(($seconds / 3600))
local seconds=$(($seconds % 3600))
local minutes=$(($seconds / 60))
local seconds=$(($seconds % 60))
local build_time="${hours}hr ${minutes}m ${seconds}s"
echo $build_time
}
function mvn_alert(){
osascript <<EOF
display notification "$1" with title "Maven" sound name "Pop"
EOF
}
@k3vinw
Copy link
Author

k3vinw commented Mar 13, 2014

Just something hacked together to popup Maven's build status on a Mac ... thought it might be fun to share in the cloud. If you want to try it, just load the script in your bash shell and alias mvn to mvn_wrapper.

@k3vinw
Copy link
Author

k3vinw commented Mar 15, 2014

Fixed a unary operator expected error when checking for mvn_color and no longer saving all git branch output to a variable before piping through awk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment