Page 1 of 1

Some terminal magic

Posted: 22 Apr 2013, 14:28
by viking60
tmux is a CLI magician but it can be a bit ...strange. You will find it in your repos.

So after you have learned how to add windows and split your windows into panes you exit and start all over again the next time you start tmux in a terminal.

That is what we have the ~/.tmux.conf file for! To open what we like every time so I happily enter the following:

Code: Select all

new -s berserk -n berserk
split-window htop
split-window
clock-mode
setw main-pane-width 55
select-layout -t 0 main-vertical
selectp -t 0

To simply open a terminal that is split into three you could alter the file like this:

Code: Select all

new -s berserk -n berserk
split-window
split-window
#clock-mode
setw main-pane-width 55
select-layout -t 0 main-vertical
selectp -t 0


That should split my berserk window in three with a clock and htop to the right.

So I happily dance away to the CLI and start tmux and..... :C Nothing :berserkf Simply one newly created window and that is it.
Here is the trick:
You need to start tmux like this to load the config file:

Code: Select all

tmux attach


And life is good
Image

If you end your session with CTRL+b and d (for detach) the last state of your tmux will be loaded the next time you start it with

Code: Select all

tmux attach


I switch between the panes with CTRL+b and o
You will get a list with CTRL+b and ? (Hold down CTRL+b and let go - then press ? within 10 sec)

Set it up to your liking and when everything is perfect do a CTRL+b and d and then add this line to your ~/.bashrc

Code: Select all

[[ $TERM != "screen" ]] && tmux attach && exit

After that the terminal pops up exactly as you left it. If you have sudo iftop running in one pane it will remember the sudo too.

To resize the panes you can hold down CTRL+b and press Left Arrow or right Arrow
Image

Re: Some terminal magic

Posted: 03 Sep 2013, 23:23
by viking60
After some use I wanted the option to use the mouse to switch and resize panes.
So i added this to the file ~/.tmux.conf

Code: Select all

set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

Then I restarted bash with

Code: Select all

source .bashrc


Now it "just works" The only thing you cannot do is to copy from one pane to another.
Here is my tmux in Guake after I had used the mouse to resize the panes:
Image

Edit: 13.11-2015
The above code wont work anymore in the latest Tmux
You can simply replace the above code with:

Code: Select all

set -g mouse on

Copy and paste between tmux panes!

Posted: 03 Sep 2013, 23:50
by viking60
So to make this perfect we need to figure out a way to copy from one pane to the other,
Bash cannot understand the vertical terminal split so it simply copies everything from the left to the far right - regardless of our nice terminal split.

If you hold down <SHIFT> an drag over the area you want to copy then it will be marked - and you can right-click that and copy it. But we need to:

    Zoom in the Pane we are copying from
    hold down shift and mark it - and copy the wanted content.
    Zoom out again - and paste the content into whatever pane we want.

To achieve this I added this to my ~/.tmux.conf

Code: Select all

unbind +
bind + \
  new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
  swap-pane -s tmux-zoom.0 \;\
  select-window -t tmux-zoom
   
unbind -
bind - \
  last-window \;\
  swap-pane -s tmux-zoom.0 \;\
  kill-window -t tmux-zoom


It assigns + and - for zooming in and out.

So standing in the pane you want to zoom in you can simply hit CTRL+b then + to zoom in.
Do your copying and zoom out again with CTRL+b then -
Edit:You can skip this part in the latest tmux - it comes with Zoom activated on CTRL-b then z
My .tmux.conf looks like this by now:

Code: Select all

new -s heidi_lap -n heidi_lap
split-window glances
split-window
# Clock
setw -g clock-mode-colour yellow
clock
setw main-pane-width 55
select-layout -t 0 main-vertical
selectp -t 0
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
#Setter opp musefunksjoner
set -g mouse on
#set -g mouse-select-pane on
#set -g mouse-resize-pane on
#set -g mouse-select-window on
#Setter opp pane-zooming for kopiering
unbind +
bind + \
  new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
  swap-pane -s tmux-zoom.0 \;\
  select-window -t tmux-zoom
   
unbind -
bind - \
  last-window \;\
  swap-pane -s tmux-zoom.0 \;\
  kill-window -t tmux-zoom
#Setter riktig tittel på maskin SSH er logget inn på
set -g set-titles on
set -g set-titles-string "#T"

After every change to .tmux.conf you should exit from all panes and exit tmux all together. then you should do a:

Code: Select all

source .bashrc

That will load your new config file when you type tmux attach again

Now this thing is perfect! +1

Video coming up in a week or so..

Re: Some terminal magic

Posted: 04 Sep 2013, 14:20
by dedanna1029
There was a terminal we used in school in the Unix class, can't remember which one, wherein there was a menu we had to use to Mark where we wanted highlighting to start, and Mark where to stop highlighting. Menu to copy/paste. I'm wondering if this might work the same way. If I still had that textbook I'd look and see exactly where that menu was, but unfortunately I sold the book back at Book Buy-back. If I can remember it, I'll post later.

Re: Some terminal magic

Posted: 04 Sep 2013, 14:58
by viking60
It works like that in tmux too.. but i wanted to use the mouse. Those key combinations were not easier to use.

Re: Some terminal magic

Posted: 10 Sep 2013, 16:30
by viking60
Video as promised:
:A

Re: Some terminal magic

Posted: 15 Nov 2015, 22:45
by dedanna1029
hhmmm... I got nada insofar as split panes. What it did do was put a "1" to the left of my prompt? I am trying to figure what I've done wrong. I chose the three panes, but without the clock, as I'm not really in need of it. What I do need is:
A root pane - for iftop or atop
Another root pane - for other root functions
A user pane - for user functions

tmux.conf:

Code: Select all

new -s dedanna -n dedanna
split-window
split-window
setw main-pane-width 55
select-layout -t 0 main-vertical
selectp -t 0

#Set mouse for copy/paste
set -g mouse on

#Pane zooming for copy/paste
unbind +
bind + \
  new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
  swap-pane -s tmux-zoom.0 \;\
  select-window -t tmux-zoom
   
unbind -
bind - \
  last-window \;\
  swap-pane -s tmux-zoom.0 \;\
  kill-window -t tmux-zoom
  s

Re: Some terminal magic

Posted: 15 Nov 2015, 23:16
by dedanna1029
Finally got it after detaching. :-P