Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to replace status bar with bash prompt displaying window number like ①. How can I get current window number in the shell?

There's TMUX_PANE env variable, unfortunately no TMUX_WINDOW.

The closest I got is: tmux display-message to flash window/pane info, then take last line of tmux show-messages and parse it. I don't want the window/pane info to flash each time the prompt is displayed.

share|improve this question
up vote 9 down vote accepted

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)"
        echo "${circled_digits:$winidx:1}"

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➤ "
share|improve this answer

All I needed was to flash and extract the tmux message when starting the shell and store this. D-oh!

tmux display-message
export TMUX_WINDOW=$(tmux show-messages | tail -1 | grep -o '\[[0-9]\] \([0-9]\)' | grep -o '[0-9]$')
PS1="$(echo $TMUX_WINDOW) \W➤ "

Now my prompt looks like:

[2] ~➤  

and what's left is to improve parsing and substitute regular digits with pretty Unicode circled digit characters - but that's another story.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .