def "_git_tool_completion" [spans: list<string>] {
    let words = ($spans | skip 1)
    let typed = ($words | drop 1)
    let partial = ($words | last)
    let reply = (with-env {_DOCOPT2_COMPLETE: "2", _DOCOPT2_WORDS: ($typed | str join (char newline))} { ^git-tool | complete | get stdout } | lines)
    let marks = ($reply | where {|line| $line | str starts-with (char tab)})
    let names = ($reply | where {|line| ($line | str length) > 0 and $line not-in $marks} | each {|line|
        let parts = ($line | split row (char tab))
        {value: ($parts | get 0), description: ($parts | get 1? | default "")}
    } | where {|candidate| $candidate.value | str starts-with $partial})
    if ($marks | is-empty) { return $names }
    if ($names | is-empty) { return null }
    $names | append (try { ls ($partial + "*" | into glob) | each {|file|
        let name = (if $file.type == dir { $file.name + "/" } else { $file.name })
        {value: ($name | to nuon), description: ""}
    } } catch { [] })
}
@complete "_git_tool_completion"
export extern "git-tool" [ ...rest: string ]
