docs: clarify shims behaviour (#3881)

* docs: clarify shims behaviour

* [autofix.ci] apply automated fixes

* removed ide integration warning

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Simon Holloway 2024-12-30 21:08:38 +00:00 committed by GitHub
parent e306720c55
commit 742fdeb44b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 45 additions and 14 deletions

View File

@ -51,6 +51,9 @@ Effectively the same as:
PATH="$HOME/.local/share/mise/shims:$PATH"
```
`mise activate --shims` does not support all the features of `mise activate`.
See <https://mise.jdx.dev/dev-tools/shims.html#shims-vs-path> for more information
### `-q --quiet`
Suppress non-error messages

View File

@ -4,6 +4,11 @@
The [beginner's guide](https://dev.to/jdxcode/beginners-guide-to-rtx-ac4), and my [blog post](https://jdx.dev/posts/2024-04-13-shims-how-they-work-in-mise-en-place/) are helpful resources to dive deeper into shims.
:::
::: warning
`mise activate --shims` does not support all the features of `mise activate`.<br>
See [shims vs path](/dev-tools/shims.html#shims-vs-path) for more info.
:::
## Introduction
There are two ways for dev tools to be loaded into your shell: `mise activate` and `shims`.
@ -77,6 +82,12 @@ but since this is only run once per shell session it's not a big deal.
## Shims vs PATH
The following features are affected when shims are used **instead** of PATH activation:
- Env vars defined in mise are only available to mise tools
- Most hooks won't trigger
- The unix `which` command points to the shim, obscuring the real executable
In general, I recommend using PATH (`mise activate`) instead of shims for _interactive_ situations. The
way activate works is every time the prompt is displayed, mise-en-place will determine what PATH and other
env vars should be and export them. This is why it doesn't work well for non-interactive situations like
@ -103,18 +114,6 @@ This may be fixable at least for some shells if they support a hook for director
some investigation will need to be done. See [#1294](https://github.com/jdx/mise/issues/1294) for details.
:::
### `which`
`which` is a command that I personally find great value in. shims effectively "break" `which` and
cause it to show the location of the shim. Of course `mise which` will show the location but I prefer
the "cleanliness" of running `which node` and getting back a real path with a version number inside of it.
e.g:
```sh
$ which node
/Users/jdx/.mise/installs/node/20/bin/node
```
### Env vars and shims
A downside of shims is the "mise environment" is only loaded when a shim is called. This means if you
@ -151,6 +150,22 @@ In general, [tasks](/tasks/) are a good way to ensure that the mise environment
this isn't a problem.
:::
### Hooks and shims
The [hooks](/hooks.html) `cd`, `enter`, `exit`, and `watch_files` only trigger with `mise activate`. However `preinstall` and `postinstall` still work with shims because they don't require shell integration.
### `which`
`which` is a command that I personally find great value in. shims effectively "break" `which` and
cause it to show the location of the shim. Of course `mise which` will show the location but I prefer
the "cleanliness" of running `which node` and getting back a real path with a version number inside of it.
e.g:
```sh
$ which node
/Users/jdx/.mise/installs/node/20/bin/node
```
## Hook on `cd`
Some version managers modify the behavior of `cd`. That might seem like the ideal method of making a version

View File

@ -79,6 +79,11 @@ Now that `mise` is installed, you can optionally activate it or add its [shims](
- [`mise activate`](/cli/activate) method updates your environment variable and `PATH` every time your prompt is run to ensure you use the correct versions.
- [Shims](dev-tools/shims.md) are symlinks to the `mise` binary that intercept commands and load the appropriate environment
::: warning
Shims do not support all the features of `mise activate`.<br>
See [shims vs path](/dev-tools/shims.html#shims-vs-path) for more info.
:::
For interactive shells, `mise activate` is recommended. In non-interactive sessions, like CI/CD, IDEs, and scripts, using `shims` might work best. You can also not use any and call `mise exec/run` directly instead.
See [this guide](dev-tools/shims.md) for more information.

View File

@ -60,7 +60,7 @@ end
:::
This assumes that `mise` is on `PATH`. If it is not, you'll need to use the absolute path (
e.g.: `eval "$($HOME/.local/bin/mise activate zsh)"`).
e.g.: `eval "$($HOME/.local/bin/mise activate zsh --shims)"`).
Here is an example showing that VSCode will use `node` provided by `mise`:

View File

@ -13,6 +13,11 @@ however that
will only setup the global tools. It won't modify the environment variables when entering into a
different project.
::: warning
`mise activate --shims` does not support all the features of `mise activate`.<br>
See [shims vs path](/dev-tools/shims.html#shims-vs-path) for more info.
:::
Also see the [shebang](/tips-and-tricks#shebang) example for a way to make scripts call mise to get
the runtime.
That is another way to use mise without activation.

View File

@ -94,7 +94,7 @@ Customize status output with `status` settings."#
}
flag "--status" help="Show \"mise: <PLUGIN>@<VERSION>\" message when changing directories" hide=true
flag "--shims" help="Use shims instead of modifying PATH\nEffectively the same as:" {
long_help "Use shims instead of modifying PATH\nEffectively the same as:\n\n PATH=\"$HOME/.local/share/mise/shims:$PATH\""
long_help "Use shims instead of modifying PATH\nEffectively the same as:\n\n PATH=\"$HOME/.local/share/mise/shims:$PATH\"\n\n`mise activate --shims` does not support all the features of `mise activate`.\nSee https://mise.jdx.dev/dev-tools/shims.html#shims-vs-path for more information"
}
flag "-q --quiet" help="Suppress non-error messages"
flag "--no-hook-env" help="Do not automatically call hook-env" {

View File

@ -43,6 +43,9 @@ pub struct Activate {
/// Effectively the same as:
///
/// PATH="$HOME/.local/share/mise/shims:$PATH"
///
/// `mise activate --shims` does not support all the features of `mise activate`.
/// See https://mise.jdx.dev/dev-tools/shims.html#shims-vs-path for more information
#[clap(long, verbatim_doc_comment)]
shims: bool,