$ tree ~/.local/bin/ -P "groovy*" -L 1
/home/cschulz/.local/bin/
├── groovy
└── groovyc -> groovy
3 directories, 2 files
$ tree ~/.local/opt -P "groovy*" -L 1
/home/cschulz/.local/opt
├── groovy-2.4.21
└── groovy-3.0.12
$ export GROOVY_VER_DEFAULT=2.4
$ groovy --version
Groovy Version: 2.4.21 JVM: 11.0.16 Vendor: Ubuntu OS: Linux
$ groovyc --version
Groovy compiler version 2.4.21
Copyright 2003-2020 The Apache Software Foundation. https://groovy-lang.org/
$ export GROOVY_VER=3.0
$ groovy --version
Groovy Version: 3.0.12 JVM: 11.0.16 Vendor: Ubuntu OS: Linux
$ groovyc --version
Groovy compiler version 3.0.12
Copyright 2003-2022 The Apache Software Foundation. https://groovy-lang.org/
Last active
September 1, 2022 17:23
-
-
Save ciis0/96abfd71bb8d330a495fc695b764dfe6 to your computer and use it in GitHub Desktop.
quite simple tool version selector (bash-based)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
SCRIPT_CALL=${BASH_SOURCE[0]} | |
SCRIPT_REAL=$(realpath $SCRIPT_CALL) | |
name=$(basename $SCRIPT_REAL) | |
ver_name=${name^^}_VER | |
ver_default_name=${ver_name}_DEFAULT | |
ver_default=${ver_default_name} | |
ver=${!ver_name:-${!ver_default_name}} | |
opt=$(dirname $SCRIPT_REAL)/../opt | |
bin=bin/$(basename $SCRIPT_CALL) | |
if [ -d $opt/$name-$ver ] | |
then $opt/$name-$ver/$bin "$@" | |
else | |
pat="$opt/$name-${ver}*/$bin" | |
if [ "$(eval ls $pat | wc -l)" -eq 1 ] | |
then | |
eval $pat '"$@"' | |
else | |
echo >&2 "tool.bash: error: $pat is not unique!" | |
exit 127 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment