From e7aa0c56e68348afefdd6af4c5bdb314a2bd6640 Mon Sep 17 00:00:00 2001 From: Fabricio Date: Thu, 30 Apr 2026 09:03:00 +0100 Subject: [PATCH] feat(fnm): add autostart option to setup fnm env (#12972) --- plugins/fnm/README.md | 28 +++++++++++++++++++++++++++- plugins/fnm/fnm.plugin.zsh | 8 ++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/fnm/README.md b/plugins/fnm/README.md index 00fab5cd4..3d3914d07 100644 --- a/plugins/fnm/README.md +++ b/plugins/fnm/README.md @@ -2,8 +2,34 @@ This plugin adds autocompletion for [fnm](https://github.com/Schniz/fnm) - a Node.js version manager. -To use it, add `fnm` to the plugins array in your zshrc file: +To use it, add `fnm` to the plugins array in your `.zshrc` file: ```zsh plugins=(... fnm) ``` + +## Configuration + +These settings should go in your `.zshrc` file, before Oh My Zsh is sourced. + +### Autostart + +If set, the plugin will automatically start fnm for the session, running the `fnm env`: + +```zsh +zstyle ':omz:plugins:fnm' autostart yes +``` + +Default: `no` (disabled) + +### Use on cd + +If set, the Node.js version will be switched based on the requirements of the current directory (recommended): + +```zsh +zstyle ':omz:plugins:fnm' use-on-cd yes +``` + +Default: `yes` (enabled) + +Check out the [official documentation](https://github.com/Schniz/fnm/blob/master/docs/commands.md) for the available fnm variables. diff --git a/plugins/fnm/fnm.plugin.zsh b/plugins/fnm/fnm.plugin.zsh index 6219025cd..90a5ae811 100644 --- a/plugins/fnm/fnm.plugin.zsh +++ b/plugins/fnm/fnm.plugin.zsh @@ -11,3 +11,11 @@ if [[ ! -f "$ZSH_CACHE_DIR/completions/_fnm" ]]; then fi fnm completions --shell=zsh >| "$ZSH_CACHE_DIR/completions/_fnm" &| + +if zstyle -t ':omz:plugins:fnm' autostart; then + local -a fnm_env_cmd + if zstyle -T ':omz:plugins:fnm' use-on-cd; then + fnm_env_cmd+=("--use-on-cd") + fi + eval "$(fnm env --shell=zsh $fnm_env_cmd)" +fi