tmux configuration #2

This commit is contained in:
CaptainArk 2016-02-02 23:20:20 +01:00
parent a1741931c8
commit 1c94323b4f
3 changed files with 52 additions and 52 deletions

View File

@ -148,7 +148,7 @@ I also use two functions with tmux (in ~/.bash_aliases).
The first one creates a new "mytmux" tmux session if one doesn't exist yet, opens 10 shells and selects the first one.
```
```bash
mytmux() {
tmux has-session -t mytmux
if [ $? != 0 ]; then
@ -170,7 +170,7 @@ mytmux() {
The second one changes the tmux window name whenever I ssh to a remote host, and switches the window name back to the name of my computer when I logout from the host.
```
```bash
if [ -n "$TMUX" ]; then
ssh() {
if [ $# -le 2 ]; then

View File

@ -237,38 +237,38 @@ bind '"' choose-window
<h2>Aliases</h2>
<p>I also use two functions with tmux (in ~/.bash_aliases).</p>
<p>The first one creates a new "mytmux" tmux session if one doesn't exist yet, opens 10 shells and selects the first one.</p>
<div class="highlight"><pre>mytmux() {
<div class="highlight"><pre>mytmux<span class="o">()</span> <span class="o">{</span>
tmux has-session -t mytmux
if [ $? != 0 ]; then
tmux new-session -s mytmux -n $(hostname) -d
tmux new-window -t mytmux:1 -n $(hostname)
tmux new-window -t mytmux:2 -n $(hostname)
tmux new-window -t mytmux:3 -n $(hostname)
tmux new-window -t mytmux:4 -n $(hostname)
tmux new-window -t mytmux:5 -n $(hostname)
tmux new-window -t mytmux:6 -n $(hostname)
tmux new-window -t mytmux:7 -n $(hostname)
tmux new-window -t mytmux:8 -n $(hostname)
tmux new-window -t mytmux:9 -n $(hostname)
tmux select-window -t mytmux:0
fi
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> !<span class="o">=</span> <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
tmux new-session -s mytmux -n <span class="k">$(</span>hostname<span class="k">)</span> -d
tmux new-window -t mytmux:1 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:2 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:3 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:4 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:5 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:6 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:7 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:8 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:9 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux <span class="k">select</span>-window -t mytmux:0
<span class="k">fi</span>
tmux attach -t mytmux
}
<span class="o">}</span>
</pre></div>
<p>The second one changes the tmux window name whenever I ssh to a remote host, and switches the window name back to the name of my computer when I logout from the host.</p>
<div class="highlight"><pre><span class="k">if</span> <span class="p">[</span> <span class="o">-</span><span class="n">n</span> <span class="s">&quot;$TMUX&quot;</span> <span class="p">];</span> <span class="n">then</span>
<span class="nf">ssh</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">[</span> <span class="err">$#</span> <span class="o">-</span><span class="n">le</span> <span class="mi">2</span> <span class="p">];</span> <span class="n">then</span>
<span class="n">tmux</span> <span class="n">rename</span><span class="o">-</span><span class="n">window</span> <span class="s">&quot;${@: -1}&quot;</span>
<span class="n">command</span> <span class="n">ssh</span> <span class="s">&quot;$@&quot;</span>
<span class="n">tmux</span> <span class="n">rename</span><span class="o">-</span><span class="n">window</span> <span class="s">&quot;$(hostname)&quot;</span>
<div class="highlight"><pre><span class="k">if</span> <span class="o">[</span> -n <span class="s2">&quot;</span>$<span class="s2">TMUX&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
ssh<span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$#</span> -le <span class="m">2</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
tmux rename-window <span class="s2">&quot;</span><span class="si">${</span><span class="p">@: -1</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="nb">command</span> ssh <span class="s2">&quot;</span><span class="nv">$@</span><span class="s2">&quot;</span>
tmux rename-window <span class="s2">&quot;</span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2">&quot;</span>
<span class="k">else</span>
<span class="n">command</span> <span class="n">ssh</span> <span class="s">&quot;$@&quot;</span>
<span class="n">fi</span>
<span class="p">}</span>
<span class="n">fi</span>
<span class="nb">command</span> ssh <span class="s2">&quot;</span><span class="nv">$@</span><span class="s2">&quot;</span>
<span class="k">fi</span>
<span class="o">}</span>
<span class="k">fi</span>
</pre></div>

View File

@ -128,38 +128,38 @@ bind &amp;#39;&amp;quot;&amp;#39; choose-window
&lt;h2&gt;Aliases&lt;/h2&gt;
&lt;p&gt;I also use two functions with tmux (in ~/.bash_aliases).&lt;/p&gt;
&lt;p&gt;The first one creates a new "mytmux" tmux session if one doesn't exist yet, opens 10 shells and selects the first one.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;mytmux() {
&lt;div class="highlight"&gt;&lt;pre&gt;mytmux&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
tmux has-session -t mytmux
if [ $? != 0 ]; then
tmux new-session -s mytmux -n $(hostname) -d
tmux new-window -t mytmux:1 -n $(hostname)
tmux new-window -t mytmux:2 -n $(hostname)
tmux new-window -t mytmux:3 -n $(hostname)
tmux new-window -t mytmux:4 -n $(hostname)
tmux new-window -t mytmux:5 -n $(hostname)
tmux new-window -t mytmux:6 -n $(hostname)
tmux new-window -t mytmux:7 -n $(hostname)
tmux new-window -t mytmux:8 -n $(hostname)
tmux new-window -t mytmux:9 -n $(hostname)
tmux select-window -t mytmux:0
fi
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; !&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
tmux new-session -s mytmux -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt; -d
tmux new-window -t mytmux:1 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:2 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:3 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:4 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:5 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:6 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:7 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:8 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux new-window -t mytmux:9 -n &lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;-window -t mytmux:0
&lt;span class="k"&gt;fi&lt;/span&gt;
tmux attach -t mytmux
}
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The second one changes the tmux window name whenever I ssh to a remote host, and switches the window name back to the name of my computer when I logout from the host.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;$TMUX&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt;
&lt;span class="nf"&gt;ssh&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="err"&gt;$#&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;le&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt;
&lt;span class="n"&gt;tmux&lt;/span&gt; &lt;span class="n"&gt;rename&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;window&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;${@: -1}&amp;quot;&lt;/span&gt;
&lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="n"&gt;ssh&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;$@&amp;quot;&lt;/span&gt;
&lt;span class="n"&gt;tmux&lt;/span&gt; &lt;span class="n"&gt;rename&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;window&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;$(hostname)&amp;quot;&lt;/span&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -n &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;$&lt;span class="s2"&gt;TMUX&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
ssh&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$#&lt;/span&gt; -le &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
tmux rename-window &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="p"&gt;@: -1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;span class="nb"&gt;command&lt;/span&gt; ssh &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
tmux rename-window &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;hostname&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="n"&gt;ssh&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;$@&amp;quot;&lt;/span&gt;
&lt;span class="n"&gt;fi&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;fi&lt;/span&gt;
&lt;span class="nb"&gt;command&lt;/span&gt; ssh &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;