Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add PowerShell example #3857

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/cli/activate.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Initializes mise in the current shell session

This should go into your shell's rc file or login shell.
Otherwise, it will only take effect in the current session.
(e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish)
(e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish, or $PROFILE for powershell)

Typically, this can be added with something like the following:

Expand Down Expand Up @@ -71,4 +71,5 @@ eval "$(mise activate bash)"
eval "$(mise activate zsh)"
mise activate fish | source
execx($(mise activate xonsh))
(&mise activate pwsh) | Out-String | Invoke-Expression
```
4 changes: 2 additions & 2 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ arg "[TASK]" help="Task to run" help_long="Task to run.\n\nShorthand for `mise t
arg "[TASK_ARGS]..." help="Task arguments" required=#false var=#true hide=#true
arg "[-- TASK_ARGS_LAST]..." required=#false var=#true hide=#true
cmd activate help="Initializes mise in the current shell session" {
long_help "Initializes mise in the current shell session\n\nThis should go into your shell's rc file or login shell.\nOtherwise, it will only take effect in the current session.\n(e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish)\n\nTypically, this can be added with something like the following:\n\n echo 'eval \"$(mise activate zsh)\"' >> ~/.zshrc\n\nHowever, this requires that \"mise\" is in your PATH. If it is not, you need to\nspecify the full path like this:\n\n echo 'eval \"$(/path/to/mise activate zsh)\"' >> ~/.zshrc\n\nCustomize status output with `status` settings."
after_long_help "Examples:\n\n $ eval \"$(mise activate bash)\"\n $ eval \"$(mise activate zsh)\"\n $ mise activate fish | source\n $ execx($(mise activate xonsh))\n"
long_help "Initializes mise in the current shell session\n\nThis should go into your shell's rc file or login shell.\nOtherwise, it will only take effect in the current session.\n(e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish, or $PROFILE for powershell)\n\nTypically, this can be added with something like the following:\n\n echo 'eval \"$(mise activate zsh)\"' >> ~/.zshrc\n\nHowever, this requires that \"mise\" is in your PATH. If it is not, you need to\nspecify the full path like this:\n\n echo 'eval \"$(/path/to/mise activate zsh)\"' >> ~/.zshrc\n\nCustomize status output with `status` settings."
after_long_help "Examples:\n\n $ eval \"$(mise activate bash)\"\n $ eval \"$(mise activate zsh)\"\n $ mise activate fish | source\n $ execx($(mise activate xonsh))\n $ (&mise activate pwsh) | Out-String | Invoke-Expression\n"
flag "-s --shell" help="Shell type to generate the script for" hide=#true {
arg <SHELL> {
choices bash elvish fish nu xonsh zsh pwsh
Expand Down
3 changes: 2 additions & 1 deletion src/cli/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use itertools::Itertools;
///
/// This should go into your shell's rc file or login shell.
/// Otherwise, it will only take effect in the current session.
/// (e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish)
/// (e.g. ~/.zshrc, ~/.zprofile, ~/.zshenv, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.config/fish/config.fish, or $PROFILE for powershell)
///
/// Typically, this can be added with something like the following:
///
Expand Down Expand Up @@ -161,5 +161,6 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
$ <bold>eval "$(mise activate zsh)"</bold>
$ <bold>mise activate fish | source</bold>
$ <bold>execx($(mise activate xonsh))</bold>
$ <bold>(&mise activate pwsh) | Out-String | Invoke-Expression</bold>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the ampersand a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this invokes the command in a non-blocking way. Background Operator

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we want that here? Isn't that going to cause the output to not even be parsed by powershell? even if it was, wouldn't it mean the next command might not have the tools setup?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also confused why it's at the beginning here but more so why we would want to background this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(mise activate pwsh) | Out-String | Invoke-Expression works just the same. But it seems Invoke-Expression -Command $(mise activate pwsh | Out-String) causes an issue with the parameter length. So the piping is preferred.
We can change it to $(mise activate pwsh) | Out-String | Invoke-Expression if it is preferred.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what @fgilcc put in the readme and we should at least be consistent. I think we should stick with what @fgilcc has unless they think we should do something different.

If we do want to change it then it would need to happen everywhere in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, I didn't even see it in the README to be honest. Sorry about that. I'm up for either approach. I'm just personally a fan of modifying my own profile script instead of a script adding it to the end. In the end, I was just following the style of the other nearby examples. I hadn't even thought to look outside the docs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifying my own profile script instead of a script adding it to the end. In the end

same here, although with mise it actually is important that it gets loaded last or else the tools might not be in the front of PATH so it's good guidance for us to just tell users to put it at the end

"#
);