This commit is contained in:
bparodi@lezzo.org 2024-10-28 19:33:41 +01:00
parent 474f0f1a04
commit 619e33196f

35
src/Which.fs Normal file
View file

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