diff --git a/sorting.sh b/sorting.sh new file mode 100644 index 0000000..bbcb818 --- /dev/null +++ b/sorting.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# regex to match any ebuild https://projects.gentoo.org/pms/8/pms.html +# [0-9]+(\.[0-9]+)+([a-z])?(_alpha|_beta|_pre|_rc|_p)?([a-z])?(-r([0-9]))?.ebuild + +function pms_sort() { + (( $# < 2 )) && if [[ -n "$1" ]]; then + echo "$1" + return 0 + else + ewarn "No version for sorting provided" "\n" + return 2 + fi + local latest="" + local args="" + args=("${@:1}") + for (( i = 1; i < $#; i++ )); do + latest="$(pms_inner_sort "${args[$i]}" "${latest:-${args[$((i - 1))]}}")" + echo "comparing: $((i - 1)) and $i" >> ./test + echo -e "args[0] = ${args[0]} and args[1] = ${args[1]} and args[2] = ${args[2]}\n" >> ./test + done + echo "$latest" +} + + +function pms_inner_sort() { + echo "first: $1" >> ./test + echo "second: $2" >> ./test + echo "$1" +} diff --git a/test b/test new file mode 100644 index 0000000..3dc040c --- /dev/null +++ b/test @@ -0,0 +1,15 @@ +first: 0.12.4 +second: 12.23.34_dev-r43 +comparing: 0 and 1 +args[0] = 12.23.34_dev-r43 and args[1] = 0.12.4 and args[2] = + +first: 0.12.4 +second: 12.23.34_dev-r43 +comparing: 0 and 1 +args[0] = 12.23.34_dev-r43 and args[1] = 0.12.4 and args[2] = 234.34.76-r6 + +first: 234.34.76-r6 +second: 0.12.4 +comparing: 1 and 2 +args[0] = 12.23.34_dev-r43 and args[1] = 0.12.4 and args[2] = 234.34.76-r6 +