···6565 let zsh = B0_env.in_scope_dir env ~/"src/tool/zsh-completion.sh" in
6666 let ml = B0_env.in_scope_dir env ~/"src/tool/cmdliner_data.ml" in
6767 let* bash = Os.File.read bash in
6868+ let bash = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" bash in
6869 let* zsh = Os.File.read zsh in
7070+ let zsh = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" zsh in
6971 let src = Fmt.str
7070- "let bash_generic_completion =\n{|%s\
7171- |}\n\n\
7272- let zsh_generic_completion =\n{|%s\
7373- |}" bash zsh
7272+ "let strf = Printf.sprintf\n\n\
7373+ let bash_generic_completion fun_name = strf\n{|%s\
7474+ |} fun_name\n\n\
7575+ let zsh_generic_completion fun_name = strf\n{|%s\
7676+ |} fun_name" bash zsh
7477 in
7578 Os.File.write ~force:true ~make_path:false ml src
7679
+5
vendor/opam/cmdliner/CHANGES.md
···1122+- cmdliner tool: add support for generating standalone completion
33+ scripts via the `--standalone-completion`. Can be used if your
44+ users don't have the cmdliner library installed (#243).
55+ Thanks to Brian Ward for suggesting.
66+27- Improve bash completion of long options with `=` (#231).
38 Thanks to Brian Ward for the patch.
49- Improve bash completion on files and directories (#238).
+8-6
vendor/opam/cmdliner/src/tool/cmdliner_data.ml
···11-let bash_generic_completion =
22-{|_cmdliner_generic() {
11+let strf = Printf.sprintf
22+33+let bash_generic_completion fun_name = strf
44+{|%s() {
35 local words cword
46 # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator
57 _get_comp_words_by_ref -n = words cword
···6769 done } < <(eval $line)
6870 return 0
6971}
7070-|}
7272+|} fun_name
71737272-let zsh_generic_completion =
7373-{|function _cmdliner_generic {
7474+let zsh_generic_completion fun_name = strf
7575+{|function %s {
7476 local w=("${words[@]}") # Keep words intact for restart completion
7577 local prefix="${words[CURRENT]}"
7678 w[CURRENT]="--__complete=${words[CURRENT]}"
···142144 _describe -V unsorted completions -U
143145 fi
144146}
145145-|}147147+|} fun_name
+56-13
vendor/opam/cmdliner/src/tool/cmdliner_main.ml
···253253 val generic_script_name : string
254254 val generic_completion : string
255255 val tool_script_name : toolname:string -> string
256256- val tool_completion : toolname:string -> string
256256+ val tool_completion : toolname:string -> standalone:bool -> string
257257end
258258259259type shell = (module SHELL)
···262262 let name = "bash"
263263 let sharedir = "bash-completion/completions"
264264 let generic_script_name = "_cmdliner_generic"
265265- let generic_completion = Cmdliner_data.bash_generic_completion
265265+ let generic_completion =
266266+ Cmdliner_data.bash_generic_completion "_cmdliner_generic"
267267+266268 let tool_script_name ~toolname = toolname
267267- let tool_completion ~toolname = strf
269269+ let tool_completion ~toolname ~standalone =
270270+ if not standalone then
271271+ strf
268272{|if ! declare -F _cmdliner_generic > /dev/null; then
269273 _completion_loader _cmdliner_generic
270274fi
271275complete -F _cmdliner_generic %s
272276|} toolname
277277+ else
278278+ let munge s = String.map (function '-' -> '_' | c -> c) s in
279279+ let fun_name = strf "_%s_cmdliner" (munge toolname) in
280280+ let fun_def = Cmdliner_data.bash_generic_completion fun_name in
281281+ strf
282282+{|
283283+%s
284284+if ! declare -F %s > /dev/null; then
285285+ _completion_loader %s
286286+fi
287287+complete -F %s %s
288288+|} fun_def fun_name fun_name fun_name toolname
273289end
274290275291module Zsh = struct
276292 let name = "zsh"
277293 let sharedir = "zsh/site-functions"
278294 let generic_script_name = "_cmdliner_generic"
279279- let generic_completion = Cmdliner_data.zsh_generic_completion
295295+ let generic_completion =
296296+ Cmdliner_data.zsh_generic_completion "_cmdliner_generic"
297297+280298 let tool_script_name ~toolname = "_" ^ toolname
281281- let tool_completion ~toolname = strf
299299+ let tool_completion ~toolname ~standalone =
300300+ if not standalone then
301301+ strf
282302{|#compdef %s
283303autoload _cmdliner_generic
284304_cmdliner_generic
285305|} toolname
306306+ else
307307+ let munge s = String.map (function '-' -> '_' | c -> c) s in
308308+ let fun_name = strf "_%s_cmdliner" (munge toolname) in
309309+ let fun_def = Cmdliner_data.zsh_generic_completion fun_name in
310310+ strf
311311+{|#compdef %s
312312+%s
313313+%s
314314+|} toolname fun_def fun_name
286315end
287316288317let shells : shell list = [(module Bash); (module Zsh)]
···292321 print_string Shell.generic_completion;
293322 Cmdliner.Cmd.Exit.ok
294323295295-let tool_completion (module Shell : SHELL) ~toolname =
324324+let tool_completion (module Shell : SHELL) ~toolname ~standalone =
296325 with_binary_stdout @@ fun () ->
297297- print_string (Shell.tool_completion ~toolname);
326326+ print_string (Shell.tool_completion ~toolname ~standalone);
298327 Cmdliner.Cmd.Exit.ok
299328300329(* Install commands *)
···317346318347let install_tool_completion
319348 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir
349349+ ~standalone_completion:standalone
320350 =
321351 with_binary_stdout @@ fun () ->
322352 let install ~dry_run ~toolnames sharedir acc (module Shell : SHELL) =
···325355 Filename.concat Shell.sharedir (Shell.tool_script_name ~toolname)
326356 in
327357 let path = Filename.concat sharedir rel_path in
328328- write_file ~dry_run path (Shell.tool_completion ~toolname);
358358+ write_file ~dry_run path (Shell.tool_completion ~toolname ~standalone);
329359 (path, rel_path) :: acc
330360 in
331361 mkdir ~dry_run (Filename.concat sharedir Shell.sharedir);
···363393364394let install_tool_support
365395 ~dry_run ~update_opam_install tools shells ~prefix ~sharedir ~mandir
396396+ ~standalone_completion
366397 =
367398 let sharedir = match sharedir with
368399 | None -> Filename.concat prefix "share" | Some sharedir -> sharedir
···375406 let toolnames = List.map snd (List.map split_toolname tools) in
376407 install_tool_completion
377408 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir
409409+ ~standalone_completion
378410379411(* Tool command listing command *)
380412···391423 let doc = "Do not install, output paths that would be written." in
392424 Arg.(value & flag & info ["dry-run"] ~doc)
393425426426+let standalone_completion =
427427+ let doc = "Generate standalone completion scripts. These scripts do \
428428+ not depend on the generic cmdliner completion scripts."
429429+ in
430430+ Arg.(value & flag & info ["standalone-completion"] ~doc)
431431+394432let update_opam_install =
395433 let doc =
396434 "Update or create an opam $(b,.install) file $(docv) with install moves \
···516554 ]
517555 in
518556 Cmd.make (Cmd.info "tool-completion" ~doc ~man) @@
519519- let+ shell = shell_pos0 and+ toolname = toolname_pos1 in
520520- tool_completion shell ~toolname
557557+ let+ shell = shell_pos0 and+ toolname = toolname_pos1
558558+ and+ standalone = standalone_completion in
559559+ tool_completion shell ~toolname ~standalone
521560522561let install_generic_completion_cmd =
523562 let doc = "Install generic completion scripts" in
···562601 (* No let punning in < 4.13 *)
563602 let+ dry_run = dry_run and+ shells = shells_opt
564603 and+ update_opam_install = update_opam_install
565565- and+ toolnames = toolnames_posleft and+ sharedir = sharedir_poslast in
604604+ and+ toolnames = toolnames_posleft and+ sharedir = sharedir_poslast
605605+ and+ standalone_completion in
566606 install_tool_completion
567607 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir
608608+ ~standalone_completion
568609569610let install_tool_manpages_cmd =
570611 let doc = "Install tool and subcommand manpages" in
···604645 in
605646 Cmd.make (Cmd.info "tool-support" ~doc ~man) @@
606647 let+ dry_run = dry_run and+ update_opam_install = update_opam_install
607607- and+ shells = shells_opt and+ tools = tools_posleft and+ sharedir = sharedir_opt
608608- and+ mandir = mandir_opt and+ prefix = prefix in
648648+ and+ shells = shells_opt and+ tools = tools_posleft
649649+ and+ sharedir = sharedir_opt and+ mandir = mandir_opt and+ prefix = prefix
650650+ and+ standalone_completion in
609651 install_tool_support
610652 ~dry_run ~update_opam_install tools shells ~prefix ~sharedir ~mandir
653653+ ~standalone_completion
611654612655let install_cmd =
613656 let doc = "Install support files for cmdliner tools" in