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."