From 619e33196f19e95ec75a517a263ae80f9c49f35b Mon Sep 17 00:00:00 2001 From: "bparodi@lezzo.org" Date: Mon, 28 Oct 2024 19:33:41 +0100 Subject: [PATCH] new file --- src/Which.fs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Which.fs diff --git a/src/Which.fs b/src/Which.fs new file mode 100644 index 0000000..273c97c --- /dev/null +++ b/src/Which.fs @@ -0,0 +1,35 @@ +module Bidello.Which + +open Sheller +open Pentole.Path + +let which (executable: string) = + let possible_shells = [ + "/bin/sh" + "/bin/bash" + "/bin/dash" + "/bin/fish" + "/usr/bin/sh" + "/usr/bin/bash" + "/usr/bin/dash" + "/usr/bin/fish" + ] + + let shell = List.tryFind (fun sh -> sh |> Path.of_string |> Result.isOk) possible_shells + + if shell |> Option.isSome then + try + Builder + .UseShell(shell.Value) + .UseExecutable("which") + .WithArgument(executable) + .ExecuteAsync () + |> Async.AwaitTask + |> Async.RunSynchronously + |> _.StandardOutput + |> _.Trim() + |> Path.of_string + |> Result.bind FileSystem.resolve + with exn -> exn.Message |> Error + else + Error "Can't find the system shell. Check your system $PATH."