From c1306033221d0cdcd8374c16bea7456a0a51ce9e Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 9 Apr 2025 17:01:38 +0200 Subject: [PATCH] modulecmd: reverse sort output of avail and search only if pattern is not the empty string --- Pmodules/modulecmd.bash.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index ae07e3f..fe37cbb 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1241,9 +1241,9 @@ get_available_modules() { fpattern=".*/${pattern}[^/]*/*[^/]+" fi local -- opt_regex='-regex' - if [[ "${mode}" != 'load' ]]; then - opt_regex='-iregex' - fi + [[ "${mode}" != 'load' ]] && opt_regex='-iregex' + local -- opt_sort='-r' + [[ -z ${pattern} ]] && opt_sort='' local -- dir='' # loop over all entries in given module path @@ -1330,7 +1330,7 @@ get_available_modules() { -regextype posix-basic \) \ \( -type f -o -type l \) \ -printf "%P\n" \ - | ${sort} -r --version-sort) + | ${sort} ${opt_sort} --version-sort) done } # get_available_modules()