# shellcheck shell=bash

gwr_set_terminal_title() {
    local tty_device
    tty_device="$(tty 2>/dev/null || true)"
    if [[ -z "$tty_device" || ! -w "$tty_device" ]]; then
        return 0
    fi

    local title
    title="$(gwr_get_current_worktree_title)"
    printf '\033]0;%s\007' "$title" >"$tty_device" 2>/dev/null || true
}
