from textwrap import dedent


def bash_unset_variable(variable_name: str):
    """Render the code to unset a variable and/or restore its backup in bash.

    :param variable_name: The name of the variable.
    :return: The code to restore and/or unset the variable.
    """
    return dedent(
        f"""\
        if [ ! -z ${{CONDA_DEVENV_BKP_{variable_name}+x}} ]; then
            export {variable_name}="$CONDA_DEVENV_BKP_{variable_name}"
            unset CONDA_DEVENV_BKP_{variable_name}
        else
            unset {variable_name}
        fi"""
    )