From 2b89e68d1e4b53c1f835b25866cdafb31f2ee276 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Sun, 25 Oct 2020 13:30:03 +0200 Subject: [PATCH] Update README for Windows instructions (#271) --- README.md | 110 ++++++++++++++++++++++----------- docs/fnm.svg | 2 +- docs/recorded_screen_script.sh | 2 +- src/log_level.rs | 2 +- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 4557133..ad4c5d5 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ ## Features +:earth_americas: Cross-platform support (Mac, Windows, Linux) + :sparkles: Single file, easy installation, instant startup :rocket: Built with speed in mind @@ -22,13 +24,15 @@ ### Using a script (MacOS/Linux) +> :wave: Hey, I'm sorry that the automated way does not support Windows yet. Feel free to contribute it! Maybe [Chocolatey](https://chocolatey.org/) or [Scoop](https://scoop.sh/)? + For `bash`, `zsh` and `fish` shells, there's an [automatic installation script](./.ci/install.sh): ```bash curl -fsSL https://fnm.vercel.app/install | bash ``` -### Upgrade +#### Upgrade On OSX, it is a simple as `brew upgrade Schniz/tap/fnm`. @@ -54,7 +58,7 @@ Example: curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir "./.fnm" --skip-shell ``` -### Manually +### Manually (OSX/Linux/Windows) #### Using Homebrew (OSX) @@ -66,39 +70,86 @@ brew install Schniz/tap/fnm Then apply the changes the installer prints, to set up your shell profile. -#### Using a release binary +#### Using a release binary (Linux/Mac/Windows) - Download the [latest release binary](https://github.com/Schniz/fnm/releases) for your system -- Make it available globally on `$PATH` -- Add the following line to your `.bashrc`/`.zshrc` file: +- Make it available globally on `PATH` environment variable +- Configure your shell profile: + + - For **Bash** or **Zsh** users, add the following to your `.bashrc`/`.zshrc` respectively: + + ```bash + eval "$(fnm env)" + ``` + + - For [**Fish Shell**](https://fishshell.com/) users, create `~/.config/fish/conf.d/fnm.fish` add this line to it: + + ```fish + fnm env | source + ``` + + - For **PowerShell** users, add the following to the end of your profile file:: + + ```powershell + fnm env --use-on-cd | Out-String | Invoke-Expression + ``` - ```bash - eval "$(fnm env)" - ``` + - On Windows, the profile is located at `~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` + - For Mac/Linux, the profile is located at `~/.config/powershell/Microsoft.PowerShell_profile.ps1` - If you are using [fish shell](https://fishshell.com/), create `~/.config/fish/conf.d/fnm.fish` add this line to it: + - For **WinCMD**, aka good old **Windows Command Prompt** or **Batch**, fnm is also supported but is not entirely covered. [You can set up a startup script](https://superuser.com/a/144348) and append the following line: - ```fish - fnm env | source - ``` + ``` + FOR /f "tokens=*" %i IN ('fnm env --use-on-cd') DO CALL %i + ``` ## Completions -- Fish Shell - [omf-plugin-fnm](https://github.com/james2doyle/omf-plugin-fnm) +fnm ships its completions with the binary: + +``` +fnm completions --shell +``` + +Where `` can be one of the supported shells: + +- `bash` +- `zsh` +- `fish` +- `powershell` + +Please follow your shell instructions to install them. ## Usage +### Global Options + +``` +fnm [--shell=fish|bash|zsh] [--node-dist-mirror=URI] [--fnm-dir=DIR] [--log-level=quiet|error|info] +``` + +- Providing `--shell=fish` will output the Fish-compliant version. Omitting it and `fnm` will try to infer the current shell based on the process tree +- Providing `--node-dist-mirror="https://npm.taobao.org/dist"` will use the Chinese mirror of Node.js +- Providing `--fnm-dir="/tmp/fnm"` will install and use versions in `/tmp/fnm` directory + You can always use `fnm --help` to read the docs: ### `fnm install [VERSION]` Installs `[VERSION]`. If no version provided, it will install the version specified in the `.node-version` or `.nvmrc` files located in the current working directory. +### `fnm install --lts` + +Installs the latest LTS version of Node + ### `fnm use [VERSION]` Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.node-version` or `.nvmrc` file located in the current working directory. +#### Flags + +- `--install-if-missing` — installs the version if it isn't installed yet + ### `fnm current` Display currently activated Node version. @@ -123,20 +174,13 @@ Aliases a Node version to a given name. Aliases a Node version as default. Uses `fnm alias` underneath. -### `fnm env [--shell=fish|bash|zsh] [--node-dist-mirror=URI] [--use-on-cd] [--fnm-dir=DIR] [--log-level=quiet|error|all]` +### `fnm env` -Prints the required shell commands in order to configure your shell, Bash compliant by default. - -- Providing `--shell=fish` will output the Fish-compliant version. Omitting it and `fnm` will try to infer the current shell based on the process tree -- Providing `--node-dist-mirror="https://npm.taobao.org/dist"` will use the Chinese mirror of Node.js -- Providing `--use-on-cd` will also output a script that will automatically change the node version if a `.node-version`/`.nvmrc` file is found -- Providing `--fnm-dir="/tmp/fnm"` will install and use versions in `/tmp/fnm` directory +Prints the required shell commands in order to configure your shell, Bash compliant if can't infer the shell. This command is highly influenced by [the global options](#global-options) -## Future Plans +#### Options: -- [ ] Feature: `fnm use --install` -- [ ] Linux: Replace `tar` with a statically linked library too (for ungzip + untar) -- [ ] Windows Support? @ulrikstrid has worked hard to make it compile on Windows, but it will probably need to have different code paths and logic. We can probably make another program and share feature tests with it, instead of relying on Windows for this very-unixy binary. +- `--use-on-cd` will also output a script that will automatically change the node version if a `.node-version`/`.nvmrc` file is found ## Contributing @@ -145,28 +189,20 @@ PRs welcome :tada: ### Developing: ``` -npm install -g esy +# Install Rust git clone https://github.com/Schniz/fnm.git cd fnm/ -esy install -esy bootstrap -esy build +cargo build ``` ### Running Binary: -After building the project, you can run the main binary that is produced. - ``` -esy x fnm.exe +cargo run -- --help # Will behave like `fnm --help` ``` ### Running Tests: ``` -# Runs some smoke-unity test -esy test - -# Runs the feature tests -feature_tests/run.sh +cargo test ``` diff --git a/docs/fnm.svg b/docs/fnm.svg index 729b998..3fa9745 100644 --- a/docs/fnm.svg +++ b/docs/fnm.svg @@ -1 +1 @@ -eval`fnmeval`fnmenv`ffnfnmfnm--versionfnm1.22.1catcat.node-version12.19.0fnminstallInstallingNodev12.19.0fnmuseUsingNodev12.19.0nodenode-vv12.19.0eevevaevaleval`eval`feval`fneval`fnmeneval`fnmenvfnm-fnm--fnm--vfnm--vefnm--verfnm--versfnm--versifnm--versioccacat.cat.ncat.nocat.nodcat.nodecat.node-cat.node-vcat.node-vecat.node-vercat.node-verscat.node-versicat.node-versiofnminfnminsfnminstfnminstafnminstalfnmusnnonodnode- \ No newline at end of file +evaleval"$(fnmeval"$(fnmenv)"ffnfnmfnm--versionfnm1.22.1catcat.node-version12.19.0fnminstallInstallingNodev12.19.0fnmuseUsingNodev12.19.0nodenode-vv12.19.0eevevaeval"eval"$eval"$(eval"$(feval"$(fneval"$(fnmeeval"$(fnmeneval"$(fnmenveval"$(fnmenv)fnm-fnm--fnm--vfnm--vefnm--verfnm--versifnm--versioccacat.cat.ncat.nocat.nodcat.nodecat.node-cat.node-vcat.node-vecat.node-vercat.node-verscat.node-versicat.node-versiofnmifnminfnminsfnminstfnminstafnmufnmusnnonodnode- \ No newline at end of file diff --git a/docs/recorded_screen_script.sh b/docs/recorded_screen_script.sh index 9c40eeb..e917ac7 100755 --- a/docs/recorded_screen_script.sh +++ b/docs/recorded_screen_script.sh @@ -9,7 +9,7 @@ function type() { echo $* | pv -qL $[10+(-2 + RANDOM%5)] } -type 'eval `fnm env`' +type 'eval "$(fnm env)"' eval `fnm env` type 'fnm --version' diff --git a/src/log_level.rs b/src/log_level.rs index 783693e..49ec4fa 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -42,7 +42,7 @@ impl std::str::FromStr for LogLevel { fn from_str(s: &str) -> Result { match s { "quiet" => Ok(Self::Quiet), - "info" => Ok(Self::Info), + "info" | "all" => Ok(Self::Info), "error" => Ok(Self::Error), loglevel => Err(format!("I don't know the log level of {:?}", loglevel)), }