Skip to content

Commit

Permalink
Show eval expression for PowerShell on native Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Aug 30, 2021
1 parent 598d969 commit 1ed2674
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,18 @@ let is_up_to_date ?skip st =

(** Returns shell-appropriate statement to evaluate [cmd]. *)
let shell_eval_invocation shell cmd =
match shell with
| SH_fish ->
(* If we are running on Windows but not Cygwin or MSYS2, suggest a shell invocation for PowerShell.
We are running in a functioning Cygwin or MSYS2 environment if and only if `cygpath` is in the PATH.
*)
let is_native_windows = Sys.win32 && Option.is_none (OpamSystem.resolve_command "cygpath") in
match is_native_windows, shell with
| true, _ ->
Printf.sprintf "(& %s) -split '\\r?\\n' | ForEach-Object { Invoke-Expression ( '$env:' + ($_ -split '; export')[0] ) }" cmd
| _, SH_fish ->
Printf.sprintf "eval (%s)" cmd
| SH_csh ->
| _, SH_csh ->
Printf.sprintf "eval `%s`" cmd
| _ ->
| _, _ ->
Printf.sprintf "eval $(%s)" cmd

(** Returns "opam env" invocation string together with optional root and switch
Expand Down

0 comments on commit 1ed2674

Please sign in to comment.