You can use display-message -p
to send the output to stdout to avoid having to extract it from the output of show-messages
:
tmux display-message -p '#I'
You could convert to the circled numbers like this (bash syntax; tested with versions 3.2.48 and 4.2.20):
circled_digits=$(printf %s \${$'\xEA',\`,{a..s}} | iconv -f UTF-16BE)
# circled_digits='⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳'
tmux_winidx_circled() {
local winidx=$(tmux display-message -p '#I')
if (( winidx > 20 )); then
echo "($winidx)"
else
echo "${circled_digits:$winidx:1}"
fi
}
The first line is nice in that it is pure ASCII; if you do not mind having non-ASCII characters in your configuration file, then you can go with the second line instead (it certainly makes the intent more obvious, assuming your editor and shell can properly handle the file’s encoding).
Then you could use it like this:
PS1="$(tmux_winidx_circled) \W➤ "