new file
This commit is contained in:
parent
474f0f1a04
commit
619e33196f
1 changed files with 35 additions and 0 deletions
35
src/Which.fs
Normal file
35
src/Which.fs
Normal 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."
|
Loading…
Reference in a new issue