Download
26 lines 658 BBashModified 2018-07-22executable raw
1234567891011121314151617181920212223242526
#!/bin/bash
while getopts ':V:L' flag; do
  case "${flag}" in
    V) VERSION=$OPTARG ;;
    L) LIST="YES" ;;
  esac
done

if [[ $VERSION ]]; then
    candidates=$(find $(dirname $BASH_SOURCE) -maxdepth 1 -name "nomsu$VERSION*")
else
    candidates=$(find $(dirname $BASH_SOURCE) -maxdepth 1 -name "nomsu[0-9]*")
fi

if [[ $LIST ]]; then
    echo "$candidates"
    exit
fi

if [[ $candidates ]]; then
    "$(echo "$candidates" | sort -V | tail -n 1)" "$@"
else
    echo "Failed to find a Nomsu version matching the regex: \"nomsu$VERSION\""
    echo "The versions available are:"
    ls $(dirname $BASH_SOURCE) | grep "^nomsu[0-9.]\+$" | sed 's/^/    * /'
fi