Dynamic Window Title - mawww/kakoune GitHub Wiki

For those of us that don't use Xorg, or can't use lemonbar, the advice in Bar won't work. However, we can achieve a similar effect by dynamically changing the title of our window.

The window title is prime real estate for helpful information. By default, it mirrors exactly the modeline. However, this is redundant, and we could use the space to display a buffer list instead. Depending on your environment, the terminal's title may be displayed in a prominent and readable position, making it an excellent candidate for displaying a buffer list.

This solution requires commit 7e05dc8, which at the time of writing is not included in the latest release, 2024.05.18. The reason is that we need the terminal_title key of the ui_options map. Before this, it was not possible to change the title of the ncurses window.

Here's an example that formats a buffer list and sets it to the window title. It excludes the *debug* buffer because that's not a buffer you can switch to by cycling. It surrounds the currently active buffer in brackets, like so: [1 *scratch* ] 2 kakrc 3 autoload/foobar.kak

define-command -hidden bar-buflist %{
    evaluate-commands %sh{
        list=''
        while read buf; do
            if [ "$buf" = '*debug*' ]; then
                continue
            fi
            index=$(($index + 1))
            if [ "$buf" = "$kak_bufname" ]; then
                cur=$(printf '[%s %s]' "$index" "$buf")
            else
                cur=$(printf '%s %s' "$index" "$buf")
            fi
            list="$list $cur"
        done <<<$(printf '%s\n' "$kak_buflist" | tr ' ' '\n')
        title="$list - $kak_client@[$kak_session]"
        printf "set-option -add global ui_options %%{terminal_title=%s}" "$title"
    }
}

This is just an example; you can (and should) decide exactly what information you want to display for yourself. You could set this command to execute on the WinDisplay event, ensuring that your buffer list is always updated:

hook global WinDisplay .* bar-buflist

The result is a buffer list that integrates quite nicely with your environment, without taking up unnecessary space, and doesn't explicitly rely on external tools, which keeps it portable. The following example shows how it looks in the Niri window manager with the window title displayed on Waybar:

image