tmux configuration #2
This commit is contained in:
parent
a1741931c8
commit
1c94323b4f
@ -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
|
||||
|
@ -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">"$TMUX"</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">"${@: -1}"</span>
|
||||
<span class="n">command</span> <span class="n">ssh</span> <span class="s">"$@"</span>
|
||||
<span class="n">tmux</span> <span class="n">rename</span><span class="o">-</span><span class="n">window</span> <span class="s">"$(hostname)"</span>
|
||||
<div class="highlight"><pre><span class="k">if</span> <span class="o">[</span> -n <span class="s2">"</span>$<span class="s2">TMUX"</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">"</span><span class="si">${</span><span class="p">@: -1</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="nb">command</span> ssh <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span>
|
||||
tmux rename-window <span class="s2">"</span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2">"</span>
|
||||
<span class="k">else</span>
|
||||
<span class="n">command</span> <span class="n">ssh</span> <span class="s">"$@"</span>
|
||||
<span class="n">fi</span>
|
||||
<span class="p">}</span>
|
||||
<span class="n">fi</span>
|
||||
<span class="nb">command</span> ssh <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span>
|
||||
<span class="k">fi</span>
|
||||
<span class="o">}</span>
|
||||
<span class="k">fi</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
|
@ -128,38 +128,38 @@ bind &#39;&quot;&#39; 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>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user