|
|
@ -1,5 +1,55 @@ |
|
|
|
open Fnm; |
|
|
|
open Fnm; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module ExportShellVarCmdGetters = { |
|
|
|
|
|
|
|
type exportCmdGetter = { |
|
|
|
|
|
|
|
getPathCmd: string => string, |
|
|
|
|
|
|
|
getMultiShellPathCmd: string => string, |
|
|
|
|
|
|
|
getFnmDirCmd: string => string, |
|
|
|
|
|
|
|
getNodeDistMirrorCmd: string => string, |
|
|
|
|
|
|
|
getLogLevelCmd: string => string, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let posixExportCmdGetter: exportCmdGetter = { |
|
|
|
|
|
|
|
getPathCmd: path => Printf.sprintf("export PATH=%s/bin:$PATH", path), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getMultiShellPathCmd: path => |
|
|
|
|
|
|
|
Printf.sprintf("export %s=%s", Config.FNM_MULTISHELL_PATH.name, path), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getFnmDirCmd: fnmDir => |
|
|
|
|
|
|
|
Printf.sprintf("export %s=%s", Config.FNM_DIR.name, fnmDir), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getNodeDistMirrorCmd: nodeDistMirror => |
|
|
|
|
|
|
|
Printf.sprintf( |
|
|
|
|
|
|
|
"export %s=%s", |
|
|
|
|
|
|
|
Config.FNM_NODE_DIST_MIRROR.name, |
|
|
|
|
|
|
|
nodeDistMirror, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLogLevelCmd: logLevel => |
|
|
|
|
|
|
|
Printf.sprintf("export %s=%s", Config.FNM_LOGLEVEL.name, logLevel), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fishExportCmdGetter: exportCmdGetter = { |
|
|
|
|
|
|
|
getPathCmd: path => Printf.sprintf("set -gx PATH %s/bin $PATH;", path), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getMultiShellPathCmd: path => |
|
|
|
|
|
|
|
Printf.sprintf("set -gx %s %s;", Config.FNM_MULTISHELL_PATH.name, path), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getFnmDirCmd: fnmDir => |
|
|
|
|
|
|
|
Printf.sprintf("set -gx %s %s;", Config.FNM_DIR.name, fnmDir), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getNodeDistMirrorCmd: nodeDistMirror => |
|
|
|
|
|
|
|
Printf.sprintf( |
|
|
|
|
|
|
|
"set -gx %s %s", |
|
|
|
|
|
|
|
Config.FNM_NODE_DIST_MIRROR.name, |
|
|
|
|
|
|
|
nodeDistMirror, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLogLevelCmd: logLevel => |
|
|
|
|
|
|
|
Printf.sprintf("set -gx %s %s", Config.FNM_LOGLEVEL.name, logLevel), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let symlinkExists = path => |
|
|
|
let symlinkExists = path => |
|
|
|
try%lwt(Lwt_unix.lstat(path) |> Lwt.map(_ => true)) { |
|
|
|
try%lwt(Lwt_unix.lstat(path) |> Lwt.map(_ => true)) { |
|
|
|
| _ => Lwt.return(false) |
|
|
|
| _ => Lwt.return(false) |
|
|
@ -90,38 +140,19 @@ let run = |
|
|
|
multishell |
|
|
|
multishell |
|
|
|
? makeTemporarySymlink() : Lwt.return(Directories.globalCurrentVersion); |
|
|
|
? makeTemporarySymlink() : Lwt.return(Directories.globalCurrentVersion); |
|
|
|
|
|
|
|
|
|
|
|
switch (shell) { |
|
|
|
let exportCmdGetter = |
|
|
|
| Bash |
|
|
|
shell === Fish |
|
|
|
| Zsh => |
|
|
|
? ExportShellVarCmdGetters.fishExportCmdGetter |
|
|
|
Printf.sprintf("export PATH=%s/bin:$PATH", path) |> Console.log; |
|
|
|
: ExportShellVarCmdGetters.posixExportCmdGetter; |
|
|
|
Printf.sprintf("export %s=%s", Config.FNM_MULTISHELL_PATH.name, path) |
|
|
|
|
|
|
|
|> Console.log; |
|
|
|
exportCmdGetter.getPathCmd(path) |> Console.log; |
|
|
|
Printf.sprintf("export %s=%s", Config.FNM_DIR.name, fnmDir) |> Console.log; |
|
|
|
exportCmdGetter.getMultiShellPathCmd(path) |> Console.log; |
|
|
|
Printf.sprintf( |
|
|
|
exportCmdGetter.getFnmDirCmd(fnmDir) |> Console.log; |
|
|
|
"export %s=%s", |
|
|
|
exportCmdGetter.getNodeDistMirrorCmd(nodeDistMirror) |> Console.log; |
|
|
|
Config.FNM_NODE_DIST_MIRROR.name, |
|
|
|
|
|
|
|
nodeDistMirror, |
|
|
|
Fnm.LogLevel.toString(logLevel) |
|
|
|
) |
|
|
|
|> exportCmdGetter.getLogLevelCmd |
|
|
|
|> Console.log; |
|
|
|
|> Console.log; |
|
|
|
Printf.sprintf( |
|
|
|
|
|
|
|
"export %s=%s", |
|
|
|
|
|
|
|
Config.FNM_LOGLEVEL.name, |
|
|
|
|
|
|
|
Fnm.LogLevel.toString(logLevel), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|> Console.log; |
|
|
|
|
|
|
|
| Fish => |
|
|
|
|
|
|
|
Printf.sprintf("set -gx PATH %s/bin $PATH;", path) |> Console.log; |
|
|
|
|
|
|
|
Printf.sprintf("set -gx %s %s;", Config.FNM_MULTISHELL_PATH.name, path) |
|
|
|
|
|
|
|
|> Console.log; |
|
|
|
|
|
|
|
Printf.sprintf("set -gx %s %s;", Config.FNM_DIR.name, fnmDir) |
|
|
|
|
|
|
|
|> Console.log; |
|
|
|
|
|
|
|
Printf.sprintf( |
|
|
|
|
|
|
|
"set -gx %s %s", |
|
|
|
|
|
|
|
Config.FNM_NODE_DIST_MIRROR.name, |
|
|
|
|
|
|
|
nodeDistMirror, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|> Console.log; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (useOnCd) { |
|
|
|
if (useOnCd) { |
|
|
|
printUseOnCd(~shell) |> Console.log; |
|
|
|
printUseOnCd(~shell) |> Console.log; |
|
|
|