<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archiwa tmux - soban</title>
	<atom:link href="https://soban.pl/category/tmux/feed/" rel="self" type="application/rss+xml" />
	<link>https://soban.pl/category/tmux/</link>
	<description>IT, Linux, Servers, Security</description>
	<lastBuildDate>Tue, 15 Apr 2025 15:00:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Dynamic Tmux Window Titles with SSH and Hostname</title>
		<link>https://soban.pl/dynamic-tmux-window-titles-with-ssh-and-hostname/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Tue, 15 Apr 2025 14:55:56 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[tmux]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=629</guid>

					<description><![CDATA[<p>Want your Tmux window titles to automatically show the hostname you connect to via SSH — and restore the local name after you disconnect? This guide will walk you through setting that up step by step. 1. Tmux configuration – ~/.tmux.conf In your Tmux configuration file, set the default shell command to a custom Bash [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/dynamic-tmux-window-titles-with-ssh-and-hostname/">Dynamic Tmux Window Titles with SSH and Hostname</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" width="1024" height="1024" src="https://soban.pl/wp-content/uploads/2025/04/image-1.png" alt="" class="wp-image-631" style="width:455px;height:auto" srcset="https://soban.pl/wp-content/uploads/2025/04/image-1.png 1024w, https://soban.pl/wp-content/uploads/2025/04/image-1-300x300.png 300w, https://soban.pl/wp-content/uploads/2025/04/image-1-150x150.png 150w, https://soban.pl/wp-content/uploads/2025/04/image-1-768x768.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p><br>Want your Tmux window titles to automatically show the hostname you connect to via SSH — and restore the local name after you disconnect? This guide will walk you through setting that up step by step.</p>



<h2 class="wp-block-heading">1. Tmux configuration – ~/.tmux.conf</h2>



<p>In your Tmux configuration file, set the default shell command to a custom Bash init file (<code>.bash_tmux</code>) that will handle window title updates.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">set-option -g default-command 'bash --rcfile ~/.bash_tmux'</pre></div>



<h2 class="wp-block-heading">2. Bash init script – ~/.bash_tmux</h2>



<p>This file runs at shell startup inside Tmux. It sets the window name to your local hostname and overrides the <code>ssh</code> command to change the window title dynamically.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#!/bin/bash
# ~/.bash_tmux
# Custom Bash init file for Tmux sessions with dynamic tab naming

# Override the default ssh command to dynamically rename the Tmux window
ssh() {
  if [ -n "$TMUX" ]; then
    # Loop through arguments to find the target host (first non-flag argument)
    for arg in "$@"; do
      if [[ "$arg" != -* ]]; then
        if [[ "$arg" == *@* ]]; then
          host="${arg#*@}"  # extract host from user@host
        else
          host="$arg"
        fi
        break
      fi
    done

    # Strip any trailing junk or whitespace
    host="$(echo "$host" | cut -d' ' -f1)"

    # Rename the Tmux window to the SSH target
    [ -n "$host" ] &amp;&amp; tmux rename-window "$host"

    # Save the local hostname to restore later
    local_host="$(hostname -s)"

    # Run the actual SSH command
    command ssh "$@"

    # Restore the original window name after logout
    tmux rename-window "$local_host"
  else
    # Not in Tmux — just run ssh normally
    command ssh "$@"
  fi
}

# Load the user's regular bash configuration
source ~/.bashrc

# On shell start, if in Tmux, set the window name to the current hostname
if [ -n "$TMUX" ]; then
  tmux rename-window "$(hostname -s)"
fi</pre></div>



<h2 class="wp-block-heading">3. Reload Tmux config without restarting</h2>



<p>To apply the changes without restarting the Tmux session, run the following:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">tmux source-file ~/.tmux.conf</pre></div>



<p>To manually reload the current shell with the new <code>.bash_tmux</code> configuration:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">exec bash --rcfile ~/.bash_tmux</pre></div>



<h2 class="wp-block-heading">4. Final result</h2>



<ul class="wp-block-list">
<li>New Tmux windows automatically show the local hostname</li>



<li>When connecting via SSH, the window is renamed to the remote host</li>



<li>When disconnecting, the original local name is restored</li>
</ul>



<p>Clean, readable, and perfect for sysadmins, devops engineers, and Tmux lovers who appreciate automatic order in their terminal tabs 💪</p>
<p>Artykuł <a href="https://soban.pl/dynamic-tmux-window-titles-with-ssh-and-hostname/">Dynamic Tmux Window Titles with SSH and Hostname</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
