ZSH helper methods and aliases

If you are developing in OpenNMS a lot, this might come in handy.

I am using Oh My Zsh and added some custom commands to my ~/.zshrc file. Check It Out!

The main commands are:

orestart() {
    ostop
    ostart
}

ostart() {
  if [ -z $OPENNMS_HOME ]; then
    OPENNMS_HOME=.
  fi

  INSTALL="false"
  while getopts "i" opt; do
    case $opt in
        i)
            INSTALL="true"
            ;;
    esac
  done

  # Install if necessary
  if [[ "$INSTALL" == "true" ]]; then
    sudo $OPENNMS_HOME/bin/runjava -s && sudo $OPENNMS_HOME/bin/install -dis
  fi

  # Start
  sudo ${OPENNMS_HOME}/bin/opennms -vt start
}

ostop() {
 if [ -z $OPENNMS_HOME ]; then
   OPENNMS_HOME=.
 fi
 sudo ${OPENNMS_HOME}/bin/opennms stop
}

ostatus() {
 if [ -z $OPENNMS_HOME ]; then
    OPENNMS_HOME=.
 fi
 sudo ${OPENNMS_HOME}/bin/opennms -v status
}

obuild() {
    if [ -d "target" ]; then
        echo "Target directory found. Deleting may require root privileges"
        sudo rm -rf target
    fi
    time (./clean.pl && ./compile.pl -DskipTests && ./assemble.pl -p dir -DskipTests); say "OpenNMS may be ready for deployment"
}

odev() {
    if [ -z $OPENNMS_HOME ]; then
        OPENNMS_HOME=.
    fi
    if [ ! -d "${OPENNMS_HOME}/jetty-webapps" ]; then
        echo "The specified directory '${OPENNMS_HOME}' does not seem to be a valid OpenNMS installation."
        return
    fi
    rm -rf ${OPENNMS_HOME}/jetty-webapps/opennms/assets
    OPENNMS_BASE="$(cd $(dirname ${OPENNMS_HOME}/../../../); pwd)"
    ln -s ${OPENNMS_BASE}/core/web-assets/target/dist/assets ${OPENNMS_HOME}/jetty-webapps/opennms/assets
    echo "org.opennms.web.assets.minified=false" > ${OPENNMS_HOME}/etc/opennms.properties.d/assets.properties
}

oassemble() {
    if [ -d "target" ]; then
        echo "Target directory found. Deleting may require root privileges"
        sudo rm -rf target
    fi
    ./assemble.pl -p dir -DskipTests
}

This allows me to very easily start/stop/build OpenNMS without having to go through the full commands all the time.

I also using some aliases for the most used Maven commands:

alias mcist="mvn clean install -DskipTests"
alias mci="mvn clean install"
1 Like