Using tmux

wblock@

Developer
Because I've mentioned it elsewhere, and people have asked:

I use sysutils/tmux for building the system:
Code:
# svn up /usr/src
# tmux
# cd /usr/src
# make -j8 buildworld

Then ctrl-b d detaches the tmux session. It won't be killed if I lose the connection to that machine. tmux attach reattaches to the session.

tmux can split the window and do all kinds of other things, but I'm generally running X and most of those things are easier to do in X with multiple windows anyway.
 
Your initial mentioning of tmux to me has really inspired me. Although I still respect and admire the sysutils/screen project I can't help share that in my personal opinion sysutils/tmux is the better of the two.

In fact; I'm so pleased with the whole thing that I decided to write up my experiences from the last week in which I replaced screen with tmux on all my FreeBSD servers. Right now I'm working on a tutorial for the forum which is nearly finished. I expect to round things up tomorrow evening or the day after.
 
Hi.

Thanks for the tip. tmux has a bad default PREFIX key: Control+b. To resolve this problem, I added these lines in my tmux.conf:

Code:
set -g prefix C-a
unbind C-b

And this one in my xorg.conf:

Code:
Option      "XkbOptions"   "ctrl:nocaps"

So I can press Caps Lock+a to send the PREFIX key to tmux.
 
bkouhi said:
tmux has a bad default PREFIX key: Control+b.
And you know why?

Because the developer was a huge sysutils/screen user as well, so he needed his software to utilize another prefix to make sure that it didn't mess up with screen itself. Although it is possible to use screen within screen (I actually did this one time) it's not an experience one will enjoy :)
 
Also, CTRL+a means "go to start of line" in many shells and text editors. It's really annoying that screen uses that for "enter command mode".

It's why all of my .screenrc files remap it to CTRL+b :)
 
OK, I checked out some screenshots, and tmux definitely looks hot! But I don't really see much difference between a terminal multiplexer and a tiling wm. Can anyone enlighten me? I read somewhere that GNU Screen can run without the X-server -- is it true?
 
jozze said:
OK, I checked out some screenshots, and tmux definitely looks hot! But I don't really see much difference between a terminal multiplexer and a tiling wm. Can anyone enlighten me?
They both more or less work the same, except one uses graphics whereas the other is console.

I read somewhere that GNU Screen can run without the X-server -- is it true?
Just like ports-mgmt/tmux they are console applications, to be used without X.
 
jozze said:
I don't really see much difference between a terminal multiplexer and a tiling wm.

You will clearly see the difference when you will have the need of using multiple terminals over an SSH connection, for example.
 
Dies_Irae said:
You will clearly see the difference when you will have the need of using multiple terminals over an SSH connection, for example.

Especially if you're trying to do some work over a crappy connection that keeps dropping out ;)

Then you can just reconnect, pick up the terminal and continue where you left off. Both screen and tmux have been life savers in this respect.
 
SirDice said:
Especially if you're trying to do some work over a crappy connection that keeps dropping out ;)

Then you can just reconnect, pick up the terminal and continue where you left off. Both screen and tmux have been life savers in this respect.

I have to confess that, being an Emacs-addicted, I tend to use it even for remote sessions, and thanks to the usage of buffers I can have multiplexity for free. Anyway, having to deal with crappy connection has been a problem for me and I solved using some kind of nohup(1) command chain. Seems interesting the solution of re-attaching the terminal once disconnected, so it is worth having a look at tmux.
 
fluca1978 said:
Seems interesting the solution of re-attaching the terminal once disconnected, so it is worth having a look at tmux.
It works really good. Applications keep running as if nothing happened. It basically just does a detach like @wblock@ showed in the first post.
 
Last edited by a moderator:
Moreover, you can create a script that opens tmux and automatically run several commands in different windows (see this for example). This way, you can open several ssh connections, run your preferred console applications (mutt, irssi), start various monitoring tools (top, tail -f mylogfile, etc.) and so on. All at once.
 
Today I've had some problems with my system. Spending a few hours without X.Org have convinced me. Time to install tmux!
 
I also like sysutils/tmux very much, very useful application.
Here is my tmux config, which includes some useful options and keybindings,
like: ctrl+alt+t — new tab, ctrl+alt+w — close tab, ctrl+pgdown/pgup — next/prev tab…
also some interface colors are changed, like tabs backgrounds, font colors, etc.
(To use this config tmux 2.6 is required.)
s8C1u9j.png

fFkDyDl.png

For best experience your terminal emulator should support 256 colors,
to force 256 colors support, launch tmux with % tmux -2.
But also it looks nice even on ttyv
9fsvq0s.png


~/.tmux.conf:
Code:
set -g default-command "${SHELL}"
set -s default-terminal screen-256color
set -s escape-time 0
set -s history-file ~/.tmux_history
set -g history-limit 100000
set -g destroy-unattached off
set -g mouse on
set -g base-index 1
set -g display-time 2000
set -g focus-events on
set -g renumber-windows on
set -g set-titles on
set -g set-titles-string "#{session_name}: [#{window_name}] #{pane_current_path}"
set -g terminal-overrides ',xterm*:Cr=\E]12;#005FAF\007:XT,rxvt*:Cr=\E]12;#005FAF\007:XT'
set -g status-keys vi
set -g status-interval 3
set -g status-justify left
set -g status-position bottom
set -wg mode-keys vi
set -wg xterm-keys on
set -wg monitor-bell on
set -wg alternate-screen on
set -wg automatic-rename on
set -wg clock-mode-colour "#00d700"
# Colors
set -g status-style "bg=#000000,fg=#d7d700"
set -g message-command-style "bg=#000000,fg=#ffffff"

set -g message-style "fg=#000000,bg=#ffffff,bold"
set -g mode-style "bg=#005faf,fg=#ffffff,bold"

set -g pane-border-style 'fg=white'
set -g pane-active-border-style 'fg=green'

set -g status-left '#[bg=#CB1B17,fg=#ffffff,bold]| #S |#[default] '
set -g window-status-format '#[bg=#808080,fg=#000000,nobold]|#I)#W#[fg=#ffd700,bold]#F#[fg=#000000]|#[default]'
set -g window-status-current-format '#[bg=#005faf] #[fg=#ffffff,bold,underscore]#I)#W#[nounderscore]#[fg=#000000]#F #[default]'
#set -g status-right '#[bg=#00d700,fg=#000000,nobold]|#(sysctl vm.loadavg | cut -d " " -f 3-5)|#[default]'
set -g status-right '#[bg=#00d700,fg=#000000,nobold]|#(cat /proc/loadavg | cut -d " " -f 1-3)|#[default]'

set -g window-status-bell-fg "#ffffff"
set -g window-status-bell-bg "#CB1B17"
# Keybindings
# use ctrl+space as prefix
unbind	C-b
set -g prefix C-space
# reload tmux configuration with prefix + r
bind r	source ~/.tmux.conf\; display ' %% source ~/.tmux.conf'
# split panes with v and h using current path
#bind v	split-window -h -c "#{pane_current_path}"
bind v	split-window -h
#bind h	split-window -v -c "#{pane_current_path}"
bind h	split-window -v
# ctrl+n/s to create/select session
bind -n	C-n new-session
bind -n	C-s choose-session
# prefix + k/K to kill current/all except current sessions
bind k	kill-session
bind K	kill-session -a
# prefix + M/m to turn on/off mouse
bind M	set-option -g mouse on\; display 'Mouse is ON'
bind m	set-option -g mouse off\; display 'Mouse turned OFF'
# shift+up to create new tab
bind -n	S-up new-window
# shift+left/right to select prev/next tab
bind -n	S-left prev
bind -n	S-right next
# alt+shift+down to kill tab
bind -n	M-S-down kill-window
# alt+shift+left/right to move tab
bind -n	M-S-left swap-window -t -1
bind -n	M-S-right swap-window -t +1
# ctrl+alt+t/w to create new/close tab
bind -n C-M-t new-window
bind -n C-M-w kill-window
# ctrl+pageup/pgdown to scroll tabs
bind -n C-Pageup prev
bind -n C-Pagedown next
# ctrl+shift+pageup/pgdown to move tabs
bind -n C-S-Pageup swap-window -t -1
bind -n C-S-Pagedown swap-window -t +1

Tips:

To apply configuration, execute
% tmux source ~/.tmux.conf (or prefix + R)
If some options won't change, you need to restart tmux:
% tmux kill-session -a && tmux kill-session
It'll kill all tmux sessions and current active session. Then start tmux.

If you want to add or change any keybindings, then execute
% tmux list-keys
It show all tmux keybindings.

To highlight text in tmux use shift+left mouse click.
j0C3By2.png


To autostart tmux with your zsh/bash/tcsh shell, add
Code:
[[ -z $TMUX ]] && exec tmux
to .zshrc/.bashrc, or add
Code:
if (! $?TMUX) exec tmux
to .tcshrc.
 
Last edited by a moderator:
That's sacrilegious, do you not care about SIGINFO? Or have you remapped that to some other key? :)
Never had any problems with this keybinding on zsh or tcsh on any terminal emulator (xterm, urxvt, stjerm...).
but if someone has any promblem,it is posible to remap, just replace
Code:
bind -n C-t new-window
with
Code:
bind -n M-t new-window
(alt+t) fore example.

Also tmux tabs shows running application process name too, so personally for me ctrl+t functionality isn't useful.
 
Also tmux tabs shows running application process name too, so personally for me ctrl+t functionality isn't useful.

tobik's pont is that on FreeBSD the canonical C-t SIGINFO binding will show useful information from different applications. With dd(1) it shows the number of bytes copied thus far; with dump(8) it gives you an estimated time to completion of the backup; with ports-mgmt/poudriere it tells you how many ports have been built, how many have failed/been ignored, how many are currently building (and which ones), and how many remain; and so on. ;)
 
With dd(1) it shows the number of bytes copied thus far...
I'm using sysutils/pv for these "tasks" and I don't use ports-mgmt/poudriere.
Also it is offtopic, anyone is free to change any keybindings to satisfy his or her needs.

UPD:
I changed new tab keybinding. So now it should work fine for 'ctrl+t' users.

By the way ctrl+t is also useful to replace letters, plus some extra info in some applications...
so I agree, it shouldn't be ignored.
 
Last edited by a moderator:
OK, I checked out some screenshots, and tmux definitely looks hot! But I don't really see much difference between a terminal multiplexer and a tiling wm. Can anyone enlighten me? I read somewhere that GNU Screen can run without the X-server -- is it true?

I can connect to my FreeBSD systems (and Debian) from my iPad (or phone) using an ssh client and run multiple terminals with tmux. That's my main reason.

Also, backgrounding big command line jobs and detaching the job and logging off while the job runs.
 
Although it is possible to use screen within screen (I actually did this one time) it's not an experience one will enjoy
I use it every day since I connect to a serial console using sysutils/screen (I find it's better than comms/minicom in certain aspects] and then run another screen in the target system. The only thing you have to do is hitting a one more time: Ctrl-a a.
Unfortunately sysutils/tmux lacks of serial connection capability...
 
OK, I checked out some screenshots, and tmux definitely looks hot! But I don't really see much difference between a terminal multiplexer and a tiling wm. Can anyone enlighten me? I read somewhere that GNU Screen can run without the X-server -- is it true?

Open a terminal in your X session. SSH to a remote server. Start tmux on that server. Now you can split the window, start multiple screens, etc, all over a single SSH connection to the remote server. And you can detach from the tmux session, leaving all those screens and programs running in the background; and that happens automatically if your SSH connection drops for any reason.

Try doing that with a tiling wm. :) You'll have multiple terminals running on your local system, each with their own SSH connection to the remote server, each that can drop at any time causing whatever you are running to be halted. There's nothing worse than starting a long-running job on a remote server and having your SSH connection die on you just minutes before the end, requiring you to start over from the beginning.

Once you start using screen/tmux on remote servers, you'll start to wonder how you ever lived without it. However, having tiled terminals on your local system is better for doing things on multiple servers, or multiple things on your local system. Of course, there's nothing stopping you from combining them both: lots of tiled terminals on your local system, connecting to remote servers, running tmux, and multiple screens on the remote system. :)

It's terminals all the way down!
 
Open a terminal in your X session. SSH to a remote server. Start tmux on that server. Now you can split the window, start multiple screens, etc, all over a single SSH connection to the remote server. And you can detach from the tmux session, leaving all those screens and programs running in the background; and that happens automatically if your SSH connection drops for any reason.

Try doing that with a tiling wm.

OK, now you have something that my wm won't do. :) Could be interesting.

Apart from that it seems a wm can handle a lot of clarity. I open terminals side by side or tiled for larger numbers, and do the same on a group of consecutive desktops so it's a quick flick between any of them - and positioned in any place or way that I want. As a way of working, I do think that the wm is often simultaneously both underused and over complicated by GUI users.
 
Try doing that with a tiling wm. :)
Lots of folks use Tmux with a tiling WM as well. I use x11-wm/dwm, and spend most of my time in Firefox and Emacs. If I need a terminal for anything, I just pull up my single terminal with a tmux session running in it. If I need to do anything fancy---like copy-paste some content from a local config file to one on a server---I can switch to a tag with just the terminal, split the Tmux window, and SSH into the server in one Tmux window and open the file,there while opening the local file in the other Tmux window. Although yes, I do have a Tmux instance running on my home server most of the time too.
 
"ahh.. connection is stable.. let's first make a dump and then install and config tmux"

Code:
% sudo dump -C32 -b64 -0uanL -h0 -f - / | gzip -2 | ssh -c blowfish usr@yadayada.xs4 dd of=rootimg.dump.gz
usr@yadayada.xs4's password:
  DUMP: Date of this level 0 dump: Sat Jan 21 22:55:11 2017
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping snapshot of /dev/vtbd0p2 (/) to standard output
  DUMP: mapping (Pass I) [regular files]
  DUMP: Cache 32 MB, blocksize = 65536
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 7440423 tape blocks.
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
load: 0.53  cmd: gzip 75256 [pipdwt] 190.87r 16.58u 0.25s 16% 2684k
  DUMP: 5.45% done, finished in 0:52 at Sat Jan 21 23:51:16 2017
load: 0.47  cmd: gzip 75256 [pipdwt] 266.43r 25.14u 0.37s 9% 2684k
  DUMP: 7.48% done, finished in 0:53 at Sat Jan 21 23:52:47 2017
load: 0.20  cmd: gzip 75256 [runnable] 525.85r 45.85u 0.86s 32% 2684k
  DUMP: 22.16% done, finished in 0:30 at Sat Jan 21 23:34:11 2017
  DUMP: 44.03% done, finished in 0:17 at Sat Jan 21 23:26:14 2017
  DUMP: 49.70% done, finished in 0:18 at Sat Jan 21 23:32:46 2017
  DUMP: 54.58% done, finished in 0:19 at Sat Jan 21 23:38:35 2017
load: 0.82  cmd: gzip 75256 [pipdwt] 1454.66r 94.29u 2.22s 2% 2684k
  DUMP: 55.00% done, finished in 0:19 at Sat Jan 21 23:39:08 2017
load: 0.25  cmd: gzip 75256 [pipdwt] 1666.14r 100.72u 2.32s 3% 2684k
  DUMP: 57.42% done, finished in 0:20 at Sat Jan 21 23:43:26 2017
  DUMP: 62.67% done, finished in 0:19 at Sat Jan 21 23:47:23 2017
load: 0.21  cmd: gzip 75256 [pipdwt] 2263.53r 119.87u 2.82s 2% 2684k
  DUMP: 67.42% done, finished in 0:18 at Sat Jan 21 23:51:03 2017
  DUMP: 72.30% done, finished in 0:16 at Sat Jan 21 23:54:12 2017
  DUMP: 74.34% done, finished in 0:16 at Sat Jan 21 23:59:19 2017
load: 0.21  cmd: gzip 75256 [pipdwt] 2915.12r 135.57u 3.15s 1% 2684k
  DUMP: 74.54% done, finished in 0:16 at Sun Jan 22 00:00:18 2017
  DUMP: 76.22% done, finished in 0:16 at Sun Jan 22 00:05:26 2017
  DUMP: 77.20% done, finished in 0:17 at Sun Jan 22 00:11:01 2017
  DUMP: 78.18% done, finished in 0:17 at Sun Jan 22 00:16:28 2017
  DUMP: 79.40% done, finished in 0:17 at Sun Jan 22 00:21:31 2017
  DUMP: 80.44% done, finished in 0:17 at Sun Jan 22 00:26:37 2017
  DUMP: 81.37% done, finished in 0:17 at Sun Jan 22 00:31:43 2017
  DUMP: 82.24% done, finished in 0:18 at Sun Jan 22 00:36:47 2017
Connection to yadayada.xs4 closed by remote host.
  DUMP: Broken pipe
  DUMP: The ENTIRE dump is aborted.

tmux > karma !
 
Back
Top