1

In tmux, how do I create a function that will set a variable that will then be available to use within tmux pane border status:

set -g pane-border-format

so I can then run that function and have the value set but only for that pane and nowhere else so that the border status displays something different for that pane and if I run that function in another pane, the pane border status will display something else but only for the pane that the function was runin

so if I run the function in pane 1 to say 'hello world' then in pane 2 to say 'goodby world' I expect pane 1 border status to say 'hello world' and pane 2 border status to say 'goodby world'.

1 Answer 1

2

I found out how to set user options, so I created a function to automate this:

if  [ -n "$TMUX" ];  then

  function set_tmux_opt {
    tmux set -q "@$1_$TMUX_PANE" "$2"
  }

fi

and it's used like this:

set_tmux_opt 'some_variable' '1'

and I get it like this:

function get_tmux_opt {
    tmux show -v "@$1_$2"
}

and used like this:

$pane_id="$1
get_tmux_opt 'some_variable' $pane_id

and then passed into the script using pane_id

4
  • Hello. Could you show a full example, i.e. how you finally set the pane-border-format so it gets reloaded with the pane-customized values? Thanks in advance.
    – bloody
    Commented Mar 31, 2023 at 19:46
  • I honestly don't recall, it's been almost 5 years since I posted this so I have no context any more.
    – Thermatix
    Commented Apr 1, 2023 at 17:53
  • OK. If you find a spare moment and try to dig out memories (or some cfg/script files) to re-associate those user options @ with setting individual pane's border text I'd be very grateful. Thanks!
    – bloody
    Commented Apr 1, 2023 at 19:00
  • So those two functions set_tmux_opt & get_tmux_opt can be used to set pane specific variables. You would on each pane set those values and then use a generic script to pull those values. So you could for example within a script set to trigger in some manner (entering the directory for example): set_tmux_opt 'git_status' "$(function_that_gets_get_status)" and then in the pane formatting do git: "$get_tmux_opt "git_status" "#{pane_id}")". Only thing is pane_id expands to the id of the active pane, there's no way to get the pane_id for the pane which the pane status bar floats above.
    – Thermatix
    Commented Apr 1, 2023 at 20:01

You must log in to answer this question.

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