# Copyright (c) 2026, Thomas Goirand <zigo@debian.org>
# Copyright (c) 2026, Infomaniak <production@infomaniak.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <https://www.gnu.org/licenses/>.

# Bash completion loader for ohr: the completion is generated
# dynamically by "ohr complete --name ohr", so this thin loader
# evals the generated glue on the first invocation; the glue
# redefines the completer and re-registers it for this shell, and
# later invocations run directly without a subprocess.

_ohr_loader()
{
    eval "$(ohr complete --name ohr 2>/dev/null)"
    if declare -f _ohr > /dev/null 2>&1 ; then
        _ohr
    fi
}

complete -F _ohr_loader ohr
