12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849(*---------------------------------------------------------------------------
Copyright (c) 2018 The b0 programmers. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)openB0_stdopenResult.Syntax(* Environment variables *)moduleEnv=structletvisual="VISUAL"leteditor="EDITOR"letinfos=letopenCmdlinerinCmd.Env.infovisual~doc:"The editor used to edit files. This is a command invocation given \
to execvp(3) and is used before EDITOR."::Cmd.Env.infoeditor~doc:"The editor used to edit files. This is a command invocation given \
to execvp(3) and is used after VISUAL."::[]end(* Editing *)typet=Cmd.tletfind?search?cmd()=matchcmdwith|Somecmd->Os.Cmd.get?searchcmd|None->letparse_envcmdsenv=matchcmdswith|Error_ase->e|Okcmdsasr->letempty_is_none=trueinmatchOs.Env.var'~empty_is_noneCmd.of_stringenvwith|Error_ase->e|OkNone->r|Ok(Somecmd)->Ok(cmd::cmds)inletcmds=Ok[Cmd.tool"nano"]inletcmds=parse_envcmdsEnv.editorinlet*cmds=parse_envcmdsEnv.visualinmatchOs.Cmd.find_first?searchcmdswith|None->Error"No runnable editor found in VISUAL or EDITOR"|Somecmd->Okcmdletedit_fileseditorfs=Os.Cmd.run_statusCmd.(editor%%pathsfs)