diff --git a/README.md b/README.md index 1a6666c..26a5811 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ ```bash eval `fnm env` ``` + + If you are using [fish shell](https://fishshell.com/), add this line to your `config.fish` file: + + ```fish + eval (fnm env --fish) + ``` ## Future Plans - [ ] Add a simpler way of installing it (`curl | bash`?) diff --git a/executable/Env.re b/executable/Env.re index 4446e0a..571ec0c 100644 --- a/executable/Env.re +++ b/executable/Env.re @@ -1,9 +1,15 @@ open Fnm; -let run = () => { - Console.log( - Printf.sprintf("export PATH=%s/bin:$PATH", Directories.currentVersion), - ); +let run = isFishShell => { + if (isFishShell) { + Console.log( + Printf.sprintf("set PATH %s/bin $PATH", Directories.currentVersion), + ); + } else { + Console.log( + Printf.sprintf("export PATH=%s/bin:$PATH", Directories.currentVersion), + ); + } Lwt.return(); }; diff --git a/executable/FnmApp.re b/executable/FnmApp.re index 64c925a..2e3965d 100644 --- a/executable/FnmApp.re +++ b/executable/FnmApp.re @@ -5,7 +5,7 @@ module Commands = { let listRemote = () => Lwt_main.run(ListRemote.run()); let listLocal = () => Lwt_main.run(ListLocal.run()); let install = version => Lwt_main.run(Install.run(~version)); - let env = () => Lwt_main.run(Env.run()); + let env = isFishShell => Lwt_main.run(Env.run(isFishShell)); }; open Cmdliner; @@ -88,8 +88,16 @@ let env = { let doc = "Show env configurations"; let sdocs = Manpage.s_common_options; let man = help_secs; + + let isFishShell = { + let doc = "Output an env configuration for fish shell."; + Arg.( + value & flag & info(["fish"], ~doc) + ); + }; + ( - Term.(const(Commands.env) $ const()), + Term.(const(Commands.env) $ isFishShell), Term.info("env", ~version, ~doc, ~exits=Term.default_exits, ~man, ~sdocs), ); };