Is there a way to rename the last tmux window created?

I'm writing a script to leverage Tmux to run some commands; however, rather than having to constantly run tmux list-windows, get a count number, and assume the last window number, I'm wondering if there's a way to just simply rename the last window that was created so that I can reference that window from its name going forward.

Here's what I'm currently doing:

last_window=$(tmux list-windows | wc -l) tmux rename-window -t session_name:$(last_window) new_window_name 

but this seems a little messy. Any thoughts?

1 Answer

I believe tmux new-window allows you to name the window when you create it. The relevant option is -n window-name.

Even if you need to rename it later (e.g. you retrieve the new name from a process in this very window somehow), you can create it with a name like some_temporary_name. Then you don't need to parse tmux list-windows to know the current name of the last window is some_temporary_name.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like