<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Tmux on Huy Minh Ha</title><link>https://minhhh.github.io/tags/tmux/</link><description>Recent content in Tmux on Huy Minh Ha</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Fri, 03 Jul 2020 00:00:00 +0700</lastBuildDate><atom:link href="https://minhhh.github.io/tags/tmux/index.xml" rel="self" type="application/rss+xml"/><item><title>Setup Tmux with Vim for Mac</title><link>https://minhhh.github.io/posts/tmux_for_mac/</link><pubDate>Fri, 03 Jul 2020 00:00:00 +0700</pubDate><guid>https://minhhh.github.io/posts/tmux_for_mac/</guid><description>&lt;h2 id="why-tmux"&gt;Why Tmux
&lt;/h2&gt;&lt;p&gt;When working on the Mac Terminal, I used to create multiple tabs. Then I can switch quickly between tabs using &lt;code&gt;Ctrl + Shift + [&lt;/code&gt; and &lt;code&gt;Ctrl + Shift + ]&lt;/code&gt;. While this works smoothly, one annoying problem is all the tabs will lose their content after reboot. So I&amp;rsquo;ve been looking for a solution that supports:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Multiple tabs. Easily switch between tabs&lt;/li&gt;
&lt;li&gt;Able to restore sessions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;From my search, it&amp;rsquo;s quite obvious that &lt;code&gt;tmux&lt;/code&gt; is the solution to my problem. Another candidate is &lt;code&gt;screen&lt;/code&gt;, which I used for running some scripts on servers, but &lt;code&gt;screen&lt;/code&gt; is pretty much a dead project now and its functions are far inferior to &lt;code&gt;tmux&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="my-tmux-settings"&gt;My tmux settings
&lt;/h2&gt;&lt;p&gt;Tmux configuration is stored inside &lt;code&gt;~/.tmux.conf&lt;/code&gt;. On startup, &lt;code&gt;tmux&lt;/code&gt; will pick up the content on this file and run it. We will put our customization code in this file.&lt;/p&gt;
&lt;p&gt;First, we will remap reload key to &lt;code&gt;r&lt;/code&gt; so that we can reload &lt;code&gt;tmux.conf&lt;/code&gt; quickly.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-gdscript3" data-lang="gdscript3"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Set reload key to r&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;bind&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;tmux&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Now, when we press &lt;code&gt;&amp;lt;prefix&amp;gt; r&lt;/code&gt;, &lt;code&gt;tmux.conf&lt;/code&gt; will be reloaded to reflect our new settings. The current &lt;code&gt;&amp;lt;prefix&amp;gt;&lt;/code&gt; is still &lt;code&gt;Ctrl B&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="remap-prefix-key"&gt;Remap prefix key
&lt;/h3&gt;&lt;p&gt;Prefix key is one of the most commonly used keys, so it&amp;rsquo;s super important to map it to a single key instead of &lt;code&gt;Ctrl B&lt;/code&gt; or &lt;code&gt;Ctrl A&lt;/code&gt; as some people might prefer.&lt;/p&gt;
&lt;p&gt;On Mac, one popular solution is to change the prefix to &lt;code&gt;Capslock&lt;/code&gt; key because it&amp;rsquo;s rarely used and very well positioned. We have 2 approaches to do this.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Approach 1: Remap &lt;code&gt;Capslock&lt;/code&gt; to &lt;code&gt;Esc&lt;/code&gt; and remap tmux &lt;code&gt;&amp;lt;prefix&amp;gt;&lt;/code&gt; to &lt;code&gt;Esc&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Go to System Preferences =&amp;gt; Keyboard =&amp;gt; Modifier keys to remap &lt;code&gt;Capslock&lt;/code&gt; to &lt;code&gt;Esc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;One annoying problem is now we have to press &lt;code&gt;Esc&lt;/code&gt; or &lt;code&gt;Capslock&lt;/code&gt; twice in Vim. This is quite unacceptable as I use Vim a lot&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Approach 2: Remap &lt;code&gt;Capslock&lt;/code&gt; to &lt;code&gt;Home&lt;/code&gt; and remap tmux &lt;code&gt;&amp;lt;prefix&amp;gt;&lt;/code&gt; to &lt;code&gt;Home&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Normally you don&amp;rsquo;t have &lt;code&gt;Home&lt;/code&gt; in Mac keyboard, but fortunately there is a software called &lt;a class="link" href="https://github.com/tekezo/Karabiner-Elements" target="_blank" rel="noopener"
 &gt;Karabiner-Elements&lt;/a&gt; that allows you to completely customize your Mac keyboard.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After that, remap tmux prefix key to &lt;code&gt;Home&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; set -g prefix Home
 bind-key Home send-prefix
 unbind C-b
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I learnt this from &lt;a class="link" href="https://blog.guilhermegarnier.com/2017/12/increasing-productivity-in-tmux-with-a-single-prefix-key/" target="_blank" rel="noopener"
 &gt;https://blog.guilhermegarnier.com/2017/12/increasing-productivity-in-tmux-with-a-single-prefix-key/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="fast-window-switching"&gt;Fast window switching
&lt;/h3&gt;&lt;p&gt;Windows in &lt;code&gt;tmux&lt;/code&gt; are the same concept as tabs in Terminal. I want to be able to switch between windows quickly without having to lift up all fingers.&lt;/p&gt;
&lt;p&gt;Fortunately, there&amp;rsquo;s an easy way to do this by mapping &lt;code&gt;next-window&lt;/code&gt; and &lt;code&gt;previous-window&lt;/code&gt; commands to &lt;code&gt;Shift Right&lt;/code&gt; and &lt;code&gt;Shift Left&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Shift arrow to switch windows
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -r -T root S-Left previous-window
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -r -T root S-Right next-window
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You just have to hold Shift and press Left or Right arrows accordingly, which makes switching very fast.&lt;/p&gt;
&lt;p&gt;Next, we also want to be able to move a window to the left and right. We&amp;rsquo;ll do this by mapping &lt;code&gt;&amp;lt;prefix&amp;gt; n&lt;/code&gt; and &lt;code&gt;&amp;lt;prefix&amp;gt; p&lt;/code&gt; to swapping a window with the one of the left or right&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Prefix n/p to move window to the left or right
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -r -T prefix n { swap-window -t +1; next-window }
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -r -T prefix p { swap-window -t -1; previous-window }
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;In effect, you will press &lt;code&gt;Capslock n&lt;/code&gt; or &lt;code&gt;Capslock p&lt;/code&gt;. However, unlike &lt;code&gt;Shift Left&lt;/code&gt; key combination, you cannot hold &lt;code&gt;Capslock&lt;/code&gt;. Instead, you will have to lift all your fingers and press 2 keys &lt;code&gt;Capslock&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; at the same time again. This is not a big problem since I&amp;rsquo;ll don&amp;rsquo;t usually move windows around a lot.&lt;/p&gt;
&lt;h3 id="restore-tmux-and-vim-sessions"&gt;Restore Tmux and Vim sessions
&lt;/h3&gt;&lt;p&gt;When it comes to restoring &lt;code&gt;tmux&lt;/code&gt; environment after system restart, the best solution is no other than &lt;a class="link" href="https://github.com/tmux-plugins/tmux-resurrect" target="_blank" rel="noopener"
 &gt;tmux-resurrect&lt;/a&gt;. The installation instruction in their website is rather easy to follow.&lt;/p&gt;
&lt;p&gt;After installing &lt;code&gt;tmux-resurrect&lt;/code&gt;, we can use &lt;code&gt;&amp;lt;prefix&amp;gt; Ctrl s&lt;/code&gt; to save, and &lt;code&gt;&amp;lt;prefix&amp;gt; Ctrl r&lt;/code&gt; to restore tmux sessions.&lt;/p&gt;
&lt;p&gt;Next and equally important, we also need a way to restore Vim session. I found &lt;a class="link" href="https://github.com/tpope/vim-obsession" target="_blank" rel="noopener"
 &gt;vim-obsession&lt;/a&gt; works well with &lt;code&gt;tmux-resurrect&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The part for tmux-resurrect in my &lt;code&gt;.tmux.conf&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# tmux-resurrect
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g @resurrect-processes &amp;#39;&amp;#34;~sudo pmset&amp;#34; &amp;#34;~Vim&amp;#34;&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g @resurrect-capture-pane-contents &amp;#39;on&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g @resurrect-strategy-vim &amp;#39;session&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Pay attention to the line &lt;code&gt;set -g @resurrect-processes '&amp;quot;~sudo pmset&amp;quot; &amp;quot;~Vim&amp;quot;'&lt;/code&gt;. There are a number of default commands such as &lt;code&gt;vi vim nvim emacs man less more tail top htop irssi weechat mutt&lt;/code&gt; that &lt;code&gt;tmux-resurrect&lt;/code&gt; will automatically restore, but other commands outside of this list will not be restored automatically. So this line tells &lt;code&gt;tmux-resurrect&lt;/code&gt; to restores extra commands if the command string match what is specified in the &lt;code&gt;@resurrect-processes&lt;/code&gt; variable. In this case, since MacVim uses the command &lt;code&gt;Vim&lt;/code&gt; and not &lt;code&gt;vim&lt;/code&gt;, we have to specify &lt;code&gt;&amp;quot;~Vim&amp;quot;&lt;/code&gt; so &lt;code&gt;tmux-resurrect&lt;/code&gt; know that it should restore Vim window. Another command I use is &lt;code&gt;sudo pmset&lt;/code&gt;, so I specify &lt;code&gt;&amp;quot;~sudo pmset&amp;quot;&lt;/code&gt; here. For more details, read &lt;a class="link" href="https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md" target="_blank" rel="noopener"
 &gt;https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Finally, there are 2 problems when you restore tmux sessions. First, if you create temporary tmux session first, so that you can run the command &lt;code&gt;&amp;lt;prefix&amp;gt; Ctrl r&lt;/code&gt; to restore previous sessions, you will have to kill the temporary session manually, which is annoying. Second, the restored windows will not have &lt;code&gt;automatic-rename&lt;/code&gt; set to &lt;code&gt;on&lt;/code&gt;, so their titles will not be updated automatically, which is equally annoying. To deal with these 2 problem, I use the following bash function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mux() {
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tmux new -d -s delete-me &amp;amp;&amp;amp; (tmux run-shell ~/.tmux/plugins/tmux-resurrect/scripts/restore.sh &amp;amp;&amp;amp; tmux kill-session -t delete-me) &amp;amp;&amp;amp;\
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (for session_window in $(tmux list-windows -a -F &amp;#39;#{session_name}:#{window_index}&amp;#39;); do
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tmux set-window-option -t $session_window automatic-rename on
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; done) &amp;amp;&amp;amp;\
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; tmux attach || tmux attach
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;This function is modified from &lt;a class="link" href="https://gist.github.com/rootulp/93f67511ae97c20c4d32b600a5ab6a8d" target="_blank" rel="noopener"
 &gt;https://gist.github.com/rootulp/93f67511ae97c20c4d32b600a5ab6a8d&lt;/a&gt;. To use it, simply type &lt;code&gt;mux&lt;/code&gt; in the terminal and it will restore previous session and reattach to it automatically. If there are multiple previous sessions, you can use &lt;code&gt;tmux a -t &amp;lt;name&amp;gt;&lt;/code&gt; to attach to the session you want.&lt;/p&gt;
&lt;h3 id="vim-binding-in-copy-mode"&gt;Vim binding in copy mode
&lt;/h3&gt;&lt;p&gt;Similar to &lt;code&gt;screen&lt;/code&gt;, &lt;code&gt;tmux&lt;/code&gt; has a copy mode to let you scroll through the content of your window, and copy/paste the parts you like.&lt;/p&gt;
&lt;p&gt;Below is the setting to make this easier&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;span class="lnt"&gt;8
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Use vim bindings in copy mode too
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-keys vi # in the status/command prompt
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;setw -g mode-keys vi
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Setup &amp;#39;v&amp;#39; to begin selection as in Vim
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -T copy-mode-vi v send-keys -X begin-selection
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel &amp;#34;reattach-to-user-namespace pbcopy&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;unbind -T copy-mode-vi Enter ; bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel &amp;#34;reattach-to-user-namespace pbcopy&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You can start the copy mode with &lt;code&gt;&amp;lt;prefix&amp;gt; [&lt;/code&gt;.
Then you navigate the window content with Vim-mode keys &lt;code&gt;h j k l&lt;/code&gt;. &lt;code&gt;v&lt;/code&gt; to start selecting. &lt;code&gt;y&lt;/code&gt; or &lt;code&gt;Enter&lt;/code&gt; to copy.&lt;/p&gt;
&lt;h3 id="customize-status-bar"&gt;Customize Status bar
&lt;/h3&gt;&lt;p&gt;The default tmux status bar position is at the top, which is ideal for showing tab-like window titles. I want to maximize the space for showing window title, so I limit the left part and right part of the status bar to very basic information.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Set Colors
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g default-terminal &amp;#34;screen-256color&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;setw -g window-status-style fg=colour254,bg=colour102
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;setw -g window-status-format &amp;#39;#I:#W &amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;setw -g window-status-current-style fg=colour254,bg=colour30,bright
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;setw -g window-status-current-format &amp;#39;#I:#W &amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Set status bar
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-bg colour252
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-fg black
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-left-length 90
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-right-length 60
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-left &amp;#34;#[fg=green]#S &amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-justify left
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g status-right &amp;#39; #[fg=green]%a %d %b %R&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The left part of status bar, specified by &lt;code&gt;status-left&lt;/code&gt;, only shows session title. The right part shows current date and time. Other colors and background colors are customized based on personal preferences.&lt;/p&gt;
&lt;h3 id="customize-window-title"&gt;Customize window title
&lt;/h3&gt;&lt;p&gt;For me, one important feature is a good window title, so that I can understand what&amp;rsquo;s in a window just by glancing at the title. One format that works quite well for me has these features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Show full path of the current directory if possible. Replace home directory with &lt;code&gt;~&lt;/code&gt; for brevity.&lt;/li&gt;
&lt;li&gt;Limit the length of the path to 20 characters so that the title is not too long&lt;/li&gt;
&lt;li&gt;But always try to show at least the full name of the current directory. This will deal with very long directory name that if truncated to 20 characters, will be hard to guess the full name.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code to achieve these features is listed below. It uses &lt;code&gt;awk&lt;/code&gt; because &lt;code&gt;awk&lt;/code&gt; is best for one-liner kinds of programs.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Set window title
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g automatic-rename on
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;set -g automatic-rename-format &amp;#34;#(echo &amp;#39;#{pane_current_path}&amp;#39; | awk &amp;#39;{split($0, a, \&amp;#34;/\&amp;#34;);basename=a[length(a)];cmd=\&amp;#34;pwd\&amp;#34;; cmd | getline homepath; close(cmd);baselength=length(basename);i=index($0,homepath);path=$0;if (i==1) { path=\&amp;#34;~\&amp;#34;substr(path,length(homepath)+1,length(path)); };maxlength=15; if (length(basename) &amp;gt; maxlength-3) { print \&amp;#34;../\&amp;#34;basename; } else if (length(path) &amp;gt; maxlength) {print \&amp;#34;..\&amp;#34;substr(path, length(path)-maxlength+3, length(path)) } else print path }&amp;#39;) - #{pane_current_command}&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;If you want to customize this code, you can change &lt;code&gt;maxlength=15&lt;/code&gt; to whatever you like. If you want to customize further, then you need to get a bit more involved with &lt;code&gt;awk&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The result is pretty good as far as I&amp;rsquo;m concerned. Here are some examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;~/work&lt;/code&gt;: Shorter than 15 characters, so it shows full path&lt;/li&gt;
&lt;li&gt;&lt;code&gt;..rk/webarchive&lt;/code&gt;: full path is &lt;code&gt;~/work/webarchive&lt;/code&gt;, so it truncates to 13 characters and replaces the rest with &lt;code&gt;..&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;../a-very-long-folder-name&lt;/code&gt;: The folder name itself is longer than 15 characters, so it&amp;rsquo;s kept in tact and then prefixed with &lt;code&gt;../&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;Those are my main points of customization of &lt;code&gt;tmux&lt;/code&gt;. Granted there are other functions that can be customized such as pane splitting, pane switching, mouse mode, etc, but I don&amp;rsquo;t use those functions much if at all in my every day activities.&lt;/p&gt;
&lt;p&gt;My tmux settings can be found at &lt;a class="link" href="https://github.com/minhhh/dotfiles/blob/master/tmux/.tmux.conf" target="_blank" rel="noopener"
 &gt;https://github.com/minhhh/dotfiles/blob/master/tmux/.tmux.conf&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>