simplification
Download
27 lines 669 BBashModified 2026-11-09executable raw
123456789101112131415161718192021222324252627
#!/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/^/    * /'
    exit 1
fi