-
Notifications
You must be signed in to change notification settings - Fork 10
/
choosenim
executable file
·23 lines (23 loc) · 1.14 KB
/
choosenim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
CHOOSE=`realpath $0` # make note of our origin
NIM=`nim --hint[Conf]:off --dump.format:json dump config | jq -r .prefixdir`/..
if [ "$NIM" = "null/.." ]; then # true when the prefixdir is missing
NIM=`dirname \`which nim\``/../.. # fallback for 1.0 support; see #127
fi
if [ $! -eq 0 ]; then # if nim threw an error due to a bad arg,
exit 1 # fail so the user can deal with it
fi
cd "$NIM"
if [ -n "$*" ]; then # a toolchain was requested
if [ -d "$*" ]; then # the toolchain is available
rm -f chosen # ffs my ln -sf should remove it
ln -sf "$*" chosen # select the chosen toolchain
if ! [ -f "chosen/bin/$CHOOSE" ]; then
cp -p "$CHOOSE" chosen/bin # install choosenim if necessary
fi
nim --version # emit current toolchain version
exit 0 # successful selection of toolchain
fi
fi
tree -v -d -L 1 --noreport # report on available toolchains
exit 1 # signify failure to switch