Skip to content

Commit

Permalink
0.8.0: adds choosenim to nimph
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Apr 6, 2020
1 parent 599d611 commit e5335dc
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ or: _How I Learned to Stop Worrying and Love the Search Path_
- wildcard, tilde, and caret semver
- absolutely zero configuration
- total interoperability with Nimble
- full-featured choosenim replacement

## Opinions

Expand Down Expand Up @@ -117,6 +118,7 @@ output (and optional repair) of the environment it finds itself in.
- [Git Subcommand Auto-Integration](https://github.com/disruptek/nimph#git-subcommands)
- [Nimble Subcommand Auto-Integration](https://github.com/disruptek/nimph#nimble-subcommands)
- [Tweaking Nimph Behavior Constants](https://github.com/disruptek/nimph#hacking)
- [Using `choosenim` to Select Nim Toolchains](https://github.com/disruptek/nimph#choosenim)
- [Nimph Module Documentation](https://github.com/disruptek/nimph#documentation)

## Demonstration
Expand Down Expand Up @@ -621,6 +623,69 @@ projects.
Compilation flags to adjust output colors/styling/emojis are found in the
project's `nimph.nim.cfg`.

## Choose Nimph, Choose Nim!

The `choosenim` tool included in Nimph allows you to easily switch a symbolic
link between adjacent Nim distributions, wherever you may have installed them.

### Installing `choosenim`
1. Install [jq](from https://stedolan.github.io/jq/) from GitHub or wherever.
1. Add the `chosen` toolchain to your `$PATH`.
1. Run `choosenim` against any of your toolchains.
```
# after installing jq however you please...
$ set --export PATH=/directory/for/all-my-nim-installations/chosen:$PATH
$ ./choosenim 1.0
Nim Compiler Version 1.0.7 [Linux: amd64]
Compiled at 2020-04-05
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: b6924383df63c91f0ad6baf63d0b1aa84f9329b7
active boot switches: -d:release
```

### Using `choosenim`
- To list available toolchains, run `choosenim`.
```
$ choosenim
.
├── 1.0
├── 1.2
├── chosen -> 1.2
├── devel
└── stable -> 1.0
```
- Switch toolchains by supplying a name or alias.
```
$ choosenim 1.2
Nim Compiler Version 1.2.0 [Linux: amd64]
Compiled at 2020-04-05
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 7e83adff84be5d0c401a213eccb61e321a3fb1ff
active boot switches: -d:release
```
```
$ choosenim devel
Nim Compiler Version 1.3.1 [Linux: amd64]
Compiled at 2020-04-05
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: b6814be65349d22fd12944c7c3d19fd8eb44683d
active boot switches: -d:release
```
```
$ choosenim stable
Nim Compiler Version 1.0.7 [Linux: amd64]
Compiled at 2020-04-05
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: b6924383df63c91f0ad6baf63d0b1aa84f9329b7
```

### Hacking `choosenim`
It's a 20-line shell script, buddy; go nuts.

## Documentation

See [the documentation for the nimph module](https://disruptek.github.io/nimph/nimph.html) as generated directly from the source.
Expand Down
20 changes: 20 additions & 0 deletions choosenim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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
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
2 changes: 1 addition & 1 deletion nimph.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.7.5"
version = "0.8.0"
author = "disruptek"
description = "nim package handler from the future"
license = "MIT"
Expand Down

0 comments on commit e5335dc

Please sign in to comment.