# Using tmux



## wblock@ (Jun 3, 2013)

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

I use sysutils/tmux for building the system:

```
# 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.


----------



## ShelLuser (Jun 3, 2013)

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.


----------



## bkouhi (Jun 3, 2013)

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:


```
set -g prefix C-a
unbind C-b
```

And this one in my xorg.conf:


```
Option      "XkbOptions"   "ctrl:nocaps"
```

So I can press Caps Lock+a to send the PREFIX key to tmux.


----------



## ShelLuser (Jun 3, 2013)

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


----------



## phoenix (Jun 3, 2013)

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


----------



## jozze (Jun 3, 2013)

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?


----------



## kpa (Jun 3, 2013)

sysutils/screen and sysutils/tmux are terminal multiplexers and have nothing to do with X.


----------



## SirDice (Jun 3, 2013)

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.


----------



## Dies_Irae (Jun 3, 2013)

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.


----------



## SirDice (Jun 4, 2013)

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.


----------



## fluca1978 (Jun 4, 2013)

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.


----------



## SirDice (Jun 4, 2013)

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.


----------



## Dies_Irae (Jun 4, 2013)

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.


----------



## jozze (Jun 18, 2013)

Today I've had some problems with my system. Spending a few hours without X.Org have convinced me. Time to install *tmux*!


----------



## Deleted member 48958 (Jan 11, 2017)

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*.)









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





~/.tmux.conf:
	
	



```
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_.





To *autostart tmux* with your zsh/bash/tcsh shell, add
	
	



```
[[ -z $TMUX ]] && exec tmux
```
to .zshrc/.bashrc, or add
	
	



```
if (! $?TMUX) exec tmux
```
to .tcshrc.


----------



## tobik@ (Jan 11, 2017)

ILUXA said:


> ctrl+t — new tab


That's sacrilegious, do you not care about SIGINFO? Or have you remapped that to some other key?


----------



## Deleted member 48958 (Jan 11, 2017)

tobik said:


> 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

```
bind -n C-t new-window
```
with

```
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.


----------



## ANOKNUSA (Jan 11, 2017)

ILUXA said:


> 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.


----------



## Deleted member 48958 (Jan 11, 2017)

ANOKNUSA said:


> 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.


----------



## ekingston (Jan 12, 2017)

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? 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.


----------



## aragats (Jan 12, 2017)

ShelLuser said:


> 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...


----------



## phoenix (Jan 20, 2017)

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? 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!


----------



## Deleted member 9563 (Jan 20, 2017)

phoenix said:


> 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.


----------



## ANOKNUSA (Jan 21, 2017)

phoenix said:


> 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.


----------



## OldskoolOrion (Jan 22, 2017)

"ahh.. connection is stable.. let's first make a dump and then install and config tmux"


```
% 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 !


----------



## wolffnx (Jan 26, 2017)

my .tmux.conf:


```
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

bind -n M-h split-window -h # Split panes horizontal
bind -n M-v split-window -v # Split panes vertically

bind -n C-M-Up resize-pane -U 1
bind -n C-M-Down  resize-pane -D 1
bind -n C-M-Left         resize-pane -L 1
bind -n C-M-Right         resize-pane -R  1
```

and a little script for open a couple of session in ssh:



```
tmux new-session 'ssh -l xx  xx.x.x.xx' \; \
    split-window -v 'ssh -l xx  xx.xx.xx.xx' \; \
    select-pane -t 0 \; \
    split-window -h 'ssh -l xx xx.xx.xx.xx' \; \
```


----------



## Deleted member 48958 (Apr 3, 2017)

Here is also nice keybinding, it is very useful when you use tmux in tmux when connected via ssh:

```
# when tmux in tmux, ctrl+q as prefix for second session
bind-key -n C-q send-prefix
```
It adds ctrl+q as prefix for second tmux session


----------



## Deleted member 48958 (Sep 15, 2017)

What I didn't like in tmux, is  its selection.
Because when you select something, after mouse button will be released,
output will be scrolled to bottom automatically... But it's very annoying IMHO (especially when you click
mouse accidentally when search something in 100 000 lines), and looks like a bug.

But here is a solution! install x11/xclip and add this to your ~/.tmux.conf:

```
# enable mouse
set -g mouse on

# use vi-like keybindings (required, or replace  "copy-mode-vi" with "copy-mode" from keybindings bellow)
set -wg mode-keys vi
# copy tmux selection to PRIMARY when selecting with mouse
bind -T copy-mode-vi	MouseDragEnd1Pane	select-pane\; send-keys -X copy-pipe 'xclip -in -selection primary'
bind -T copy-mode-vi	DoubleClick1Pane	select-pane\; send-keys -X select-word\; send-keys -X copy-pipe 'xclip -in -selection primary'
bind -T copy-mode-vi	TripleClick1Pane	select-pane\; send-keys -X select-line\; send-keys -X copy-pipe 'xclip -in -selection primary'

# mouse wheel scroll clears selection
bind -T copy-mode-vi	WheelUpPane		send-keys -X clear-selection\; send-keys -X -N 3 scroll-up
bind -T copy-mode-vi	WheelDownPane		send-keys -X clear-selection\; send-keys -X -N 3 scroll-down


# clear selection (and move cursor) with left click
bind -T copy-mode-vi	MouseDown1Pane		select-pane \; send-keys -X clear-selection

# paste tmux selection with middle click
bind -T root		MouseDown2Pane		paste-buffer

# space to start selection and copy it to PRIMARY
bind -T copy-mode-vi	Space			send-keys -X copy-pipe 'xclip -in -selection primary'\; send-keys -X begin-selection

# y - copy to CLIPBOARD
bind -T copy-mode-vi	y			send-keys -X copy-pipe 'xclip -in -selection clipboard'\; send-keys -X clear-selection

# q - clear selection
bind -T copy-mode-vi	q			send-keys -X clear-selection

# press escape to exit copy mode
bind -T copy-mode-vi	Escape			send-keys -X cancel

# home & end in copy mode
bind -T copy-mode-vi	Home			send -X start-of-line
bind -T copy-mode-vi	End			send -X end-of-line

# ctrl+right/left in copy mode
bind -T copy-mode-vi	C-Right			send-keys -X next-word
bind -T copy-mode-vi	C-Left			send-keys -X previous-word
```
Then execute `% tmux source ~/.tmux.conf` or restart tmux (`% tmux kill-session -a && tmux kill-session`).
Now tmux selection will be added to *PRIMARY* selection automatically,
so it is possible to paste selected output with shift + insert/middle mouse click.
Also now, finally, output won't be scrolled to the bottom after mouse selection!
So now tmux selection works almost like in a regular terminal!
Tested with tmux-2.6.

Also do not forget that it is possible to search in tmux, and it is quite handy,
just press "/" when you're using "copy mode" in tmux. To start copy mode, press prefix - [.
Also it is possible to start copy mode with  prefix - PageUp or mouse wheel scroll.


----------



## Deleted member 48958 (Oct 30, 2017)

Also it is possible to configure sysutils/tmux to change your terminal emulator titles.
Man page says that you just need to add 
	
	



```
set -g set-titles on
set -g set-titles-string "#{session_name}: [#{window_name}] #{pane_current_path}"
```
 to ~/.tmux.conf. But this doesn't work as expected.
To make it work with xterm and urxvt, you also need to add 
	
	



```
set -g terminal-overrides ',xterm*:XT,rxvt*:XT'
```


----------



## nickednamed (Oct 31, 2017)

Just thought I'd let people know, in case they didn't, that there is a pair of tools which, together, provide similar functionality to screen / tmux: dvtm and abduco.

dvtm is more of a "tiling window manager for the console", while abduco is strictly a session management tool.


----------



## Deleted member 48958 (Oct 31, 2017)

nickednamed said:


> dvtm is more of a "tiling window manager for the console", while abduco is strictly a session management tool.


And for tabs management you, also, need terminal emulator with tabs support,
so why not to use one tool, that should replace 3? Considering that it is still very lightweight and very useful.

Aslo, tmux comes preinstalled on OpenBSD, and, even, as far as I remebmer, on Ubuntu server(s) (and, it seems, on new RHEL too).


----------



## Deleted member 48958 (Jul 18, 2018)

Here is my current sysutils/tmux configuration, I like it much,
it changes xterm and urxvt titles to some useful info, also it changes
cursor color, it uses x11/xclip to copy highlighted text to PRIMARY or CLIPBOARD.
Also some useful keybindings present and nice colors 





~/.tmux.conf:

```
set -s default-terminal screen-256color
set -s history-file ~/.tmux_history
set -s escape-time 0
set -g default-command "${SHELL}"
set -g history-limit 100000
set -g destroy-unattached off
set -g mouse on
set -g base-index 1
set -g display-time 3000
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;green\007:XT,rxvt*:Cr=\E]12;green\007:XT'
set -g status on
set -g status-keys vi
set -g status-interval 5
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 word-separators ' ()<>[]{}|=,;:&?*@^"'
set -wg clock-mode-colour green
# Colors
set -g status-style "bg=#000000"
set -g message-command-style "bg=#000000,fg=#00d700"
set -g message-style "fg=#000000,bg=#00d700"
set -g mode-style "fg=#ff0000,bold"
set -g pane-border-style 'fg=#ffffff'
set -g pane-active-border-style 'fg=#ff0000'
set -g status-left ' #[fg=#ff0000,bold]#S:#[default]'
set -g window-status-format ' #[fg=#b2b2b2]#I-#W#[fg=#ffff00,bold]#F#[fg=#000000]#[default]'
set -g window-status-current-format ' #[fg=#005fff,bold]#I-#W#F#[default]'
set -g window-status-bell-fg "#ffffff"
set -g window-status-bell-bg "#ff0000"
set -g status-right '#[fg=#ffd700,bold] #(sysctl vm.loadavg | cut -d \  -f 3-5) #[default]'
# Keybindings
# use ctrl+space as prefix and ctrl+a as prefix for second tmux session
set -g prefix C-space
bind-key -n C-a send-prefix
unbind  C-b
# reload tmux configuration with prefix+r
bind r source ~/.tmux.conf\; display ' Configuration RELOADED'
# split panes with prefix+v or h using current path
bind v split-window -h -c "#{pane_current_path}"
bind h split-window -v -c "#{pane_current_path}"
# prefix+N to create new session
bind N new-session
# prefix+d to close current tab
bind d kill-window
# prefix+k/K to kill current/all except current session
bind k  kill-session
bind K  kill-session -a
# prefix+m to turn on/off mouse
bind m  set-option -g mouse\; display ' Mouse #{?mouse,ENABLED,DISABLED}'
# prefix+/ to search
bind / copy-mode\; send-key ?
# alt+shift+up/down to create new/close tab
bind -n M-S-up new-window
bind -n M-S-down kill-window
# alt+shift+left/right to select prev/next tab
bind -n M-S-left prev
bind -n M-S-right next
# ctrl+shift+left/right to move tab
bind -n C-S-left swap-window -t -1
bind -n C-S-right swap-window -t +1
# 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
# ctrl+alt+n/s to create/select session
bind -n C-M-n new-session
bind -n C-M-s choose-session
# ctrl+alt+t/w to create new/close tab
bind -n C-M-t new-window
bind -n C-M-w kill-window
# ctrl+alt+pageup/pgdown to scroll tabs
bind -n C-M-Pageup prev
bind -n C-M-Pagedown next
# ctrl+alt+a to toggle status line
bind -n C-M-a set -g status

# copy tmux selection to PRIMARY when selecting with mouse
bind -T copy-mode-vi    MouseDragEnd1Pane    select-pane\; send-keys -X copy-pipe 'xclip -in -selection primary'
bind -T copy-mode-vi    DoubleClick1Pane     select-pane\; send-keys -X select-word\; send-keys -X copy-pipe 'xclip -in -selection primary'
bind -T copy-mode-vi    TripleClick1Pane     select-pane\; send-keys -X select-line\; send-keys -X copy-pipe 'xclip -in -selection primary'
# mouse wheel scroll clears selection
bind -T copy-mode-vi    WheelUpPane          send-keys -X clear-selection\; send-keys -X -N 3 scroll-up
bind -T copy-mode-vi    WheelDownPane        send-keys -X clear-selection\; send-keys -X -N 3 scroll-down
# clear selection (and move cursor) with left click
bind -T copy-mode-vi    MouseDown1Pane       select-pane \; send-keys -X clear-selection
# paste tmux selection with middle click
bind -T root    MouseDown2Pane               paste-buffer
# v - start selection and auto copy it to PRIMARY
bind -T copy-mode-vi    v                    send-keys -X copy-pipe 'xclip -in -selection primary'\; send-keys -X begin-selection
# y - copy to CLIPBOARD when in copy mode
bind -T copy-mode-vi    y                    send-keys -X copy-pipe 'xclip -in -selection clipboard'\; send-keys -X clear-selection
# q - quit copy mode
bind -T copy-mode-vi    q                    send-keys -X cancel
# escape - clear selection in copy mode
bind -T copy-mode-vi    Escape               send-keys -X clear-selection
# home & end in copy mode
bind -T copy-mode-vi    Home                 send -X start-of-line
bind -T copy-mode-vi    End                  send -X end-of-line
# ctrl+right/left in copy mode
bind -T copy-mode-vi    C-Right              send-keys -X next-word
bind -T copy-mode-vi    C-Left               send-keys -X previous-word
```


----------



## Lamia (Jul 18, 2018)

It would be good to read the configs and the experience of a user of tmux and fvwm2. I have fvwm2 as my desktop manager but it is proving difficult to use. ATM, tmux appears capable of achieving most of the tasks I would want fvwm2 to do - opening terminals, launching apps/clients, etc.

I would rather want to use one tmux instance to run multiple terminals at different fvwm2 decks/pages. Yet, I would want to use the same keybindings for both of them. I have learnt and forgotten so many keybindings as I used (preferably jumped from) yakuake, terminator, emacs to fvwm2+tmux


----------



## Deleted member 48958 (Jul 18, 2018)

Lamia said:


> It would be good to read the configs and the experience of a user of tmux and fvwm2. I have fvwm2 as my desktop manager but it is proving difficult to use. ATM, tmux appears capable of achieving most of the tasks I would want fvwm2 to do - opening terminals, launching apps/clients, etc.
> 
> I would rather want to use one tmux instance to run multiple terminals at different fvwm2 decks/pages. Yet, I would want to use the same keybindings for both of them. I have learnt and forgotten so many keybindings as I used (preferably jumped from) yakuake, terminator, emacs to fvwm2+tmux



FVWM doesn't related anyhow to tmux and tmux doesn't related anyhow to FVWM,
it is two completely different applications, tmux is a BSD licensed terminal multiplexer,
and FVWM is a GPL licensed window manager, there is no connection between them.

But if you really want to use these applications, start with FVWM and tmux manual pages,
launch it with `% man fvwm` and `% man tmux`, these manual pages are pretty complete,
so it includes a lot of useful information.


----------



## Lamia (Jul 19, 2018)

ILUXA said:


> FVWM doesn't related anyhow to tmux and tmux doesn't related anyhow to FVWM,
> it is two completely different applications, tmux is a BSD licensed terminal multiplexer,
> and FVWM is a GPL licensed window manager, there is no connection between them.


Thanks ILUXA, I got a better picture of TMUX awhile ago before reading this reply. There are however some interesting extensions in TMUX to check out - scct, tmux-cpu-mem-load and wemux.


----------



## Lamia (Jul 19, 2018)

I am liking this tool. It will reduce the number of decks/panels/pages needed.  But at the moment, as I build & install it with postmaster, it is adding perl 5.24 to the existing Perls(5.26 & site_*).

I am wanting to rebuild it with the default version set to 5.26 set in make.conf. Any warnings from the community?


----------



## rufwoof (Jul 19, 2018)

Basic tmux Tutorial, Part 2 - Shared Sessions


----------



## Lamia (Jul 19, 2018)

Lamia said:


> I am liking this tool. It will reduce the number of decks/panels/pages needed.  But at the moment, as I build & install it with postmaster, it is adding perl 5.24 to the existing Perls(5.26 & site_*).
> 
> I am wanting to rebuild it with the default version set to 5.26 set in make.conf. Any warnings from the community?


I might have found an answer to this enquiry. It must be one of the tmux extensions requiring the old Perl.


----------



## Lamia (Aug 7, 2018)

I am wondering of it is possible to autostart tmux on boot as a service. I have tried it.
This is an excerpt of my rc.d/customtmux script.


```
rcvar=customtmux_enable

load_rc_config "$name"


: ${customtmux_enable:="NO"}

startcommand="/bin/sh -c '/usr/local/bin/tmux new-session -s host'"
```
 But it won't run. Placing a line like 'tmux doas....' in .cshrc/.zshrc/.profile/.bash_profile won't work too.

I have also considered sysutils/wemux but I don't think it would do it. Isn't it possible to start a terminal as a service on boot without a human intervention?  I would like have a tmux session running on (re)starting my box.


----------



## Deleted member 48958 (Aug 7, 2018)

Lamia said:


> But it won't run. Placing a line like 'tmux doas....' in .cshrc/.zshrc/.profile/.bash_profile won't work too.


Add 

```
[[ -z $TMUX ]] && exec tmux
```
to your ~/.bashrc, if your login shell is bash,
or to ~/.zshrc, if your login shell is zsh,
or add

```
if (! $?TMUX) exec tmux
```
to ~/.cshrc, if you use tcsh.
To change your login shell, execute `% chsh`, then edit "_Shell:_" line and relogin.


----------



## Deleted member 48958 (Sep 20, 2018)

To make your tmux config usable on different operating systems,
it is possible to use "if-shell" in your ~/.tmux.conf file,
For example, to use different "status-right" on different OS-es,
add this to your config:
	
	



```
# different right status line for FreeBSD and Linux
if-shell 'test "$(uname)" = "FreeBSD"' 'set -g status-right "#[fg=#ffd700,bold] #(sysctl vm.loadavg | cut -c 14-28) #[default]"'
if-shell 'test "$(uname)" = "Linux"' 'set -g status-right "#[fg=#00d700,bold]#(cat /proc/loadavg | tr . , | cut -c 1-14) #[default]"'
```
It is possible to do the same with prefix, etc.
	
	



```
# use ctrl+a as prefix for FreeBSD and ctrl+space for Linux
if-shell 'test "$(uname)" = "FreeBSD"' 'set -g prefix C-a'
if-shell 'test "$(uname)" = "Linux"' 'set -g prefix C-space'
unbind  C-b
```
Different prefixes are useful when you're using tmux in tmux when using ssh.


----------



## Lamia (Sep 21, 2018)

ILUXA said:


> Add
> 
> ```
> [[ -z $TMUX ]] && exec tmux
> ...


It did not do the trick. TMUX does not start on booting or logging in. I use cshrc and did as you instructed. I also tried the security/doas for different users but no luck. TMUX only starts when I manually start it.


----------



## Deleted member 48958 (Sep 21, 2018)

Lamia said:


> It did not do the trick. TMUX does not start on booting or logging in. I use cshrc and did as you instructed. I also tried the security/doas for different users but no luck. TMUX only starts when I manually start it.


There is no need in doas or sudo or something else,
because tmux shouldn't be launched as root,
create EMPTY ~/.cshrc with only one line inside --

```
if (! $?TMUX) exec tmux
```
Then start terminal session. Tmux session will be launched 100%.
Or install zsh, set it as your login shell (execute `% chsh -s /usr/local/bin/zsh`)
and re-login, then add "_[[ -z $TMUX ]] && exec tmux_" to ~/.zshrc.

To find out what shell you're using now, execute `% echo $0`.


----------



## kpedersen (Sep 21, 2018)

I use this in my .bashrc on FreeBSD and .profile on OpenBSD.
I don't actually know what the side effect of using exec is in a .profile but it seems to work for now.


```
if [ -z "$TMUX" ]; then
  tmux has-session >/dev/null 2>&1
  RC=$?

  if [ $RC = 0 ]; then
    exec tmux attach
  else
    exec tmux
  fi
fi
```

Basically it goes like:

If not running in tmux already ($TMUX variable)
Check if there is a session running by storing error code from the "has-session" parameter to tmux
If there was no "error" (RC = 0) then attempt to attach
If there was an "error" (RC != 0) then start a fresh tmux
You might also like to do this only for the first tty so something like:


```
if [ "`tty`" = "/dev/tty1" ]; then
  # do the tmux stuff
fi
```

Though I personally just call startx if I log in on my first TTY.


----------



## Deleted member 48958 (Sep 21, 2018)

IMO it's not very practical to attach to existing tmux session every
time when starting new terminal session. If you don't want to have
many tmux sessions running, better use $TMOUT variable
with your zsh or bash shell:
	
	



```
# autologout when no commands were entered for one hour
export TMOUT=3600
```
With tcsh shell use:
	
	



```
set autologout = 60        # autologout after one hour of inactivity
```
Then tmux sessions will be automatically closed, if you don't use it.
Also it is very easy to switch sessions when using tmux, use "prefix+*s*",
or to destroy existing session — use prefix+*s* to show session list,
then highlight session and use prefix + *:*. Then enter "kill-session"
and confirm.


----------



## Lamia (Sep 22, 2018)

I actually use "sh". So, I modified the above to:

```
if [ -z "$TMUX" ]; then
  exec tmux new-session -s host
fi
```


----------



## Deleted member 48958 (Sep 24, 2018)

Lamia said:


> I actually use "sh".


It is not the best idea to use /bin/sh as interactive shell,
because it is a scripting shell, so use it for scripts.
You're missing a lot of nice features while using sh,
For example, to manipulate files in zsh, bash and tcsh
it is possible to use: `% cp /usr/local/dir/{file1,file2}`,
this command will copy _file1_ to _file2_, or to rename file,
use `% mv /usr/local/dir/file1{,.bak}` this command
will rename _file1_ to _file1.bak_. You're missing a lot of other features
also. I suggest you to try shells/zsh, it is very customizable and usable.
You can try to use it with my config -
https://forums.freebsd.org/threads/share-your-zshrc-file.62653/


----------



## Lamia (Sep 25, 2018)

ILUXA said:


> It is not the best idea to use /bin/sh as interactive shell,
> because it is a scripting shell, so use it for scripts.
> You're missing a lot of nice features while using sh,
> For example, to manipulate files in zsh, bash and tcsh
> ...


Thanks ILUXA, I like those shortcuts.  I will soon give zsh with your config a shot.


----------



## kpedersen (Sep 25, 2018)

I don't believe anything in my shell code snippet above needed changing for /bin/sh because that is what I always target for my scripts.
Remember, things like '[' and ']' are actually separate programs that sh runs.


----------



## Deleted member 48958 (Sep 25, 2018)

IMO, using /bin/sh as interactive shell is like using old single-speed bicycle, while using zsh is like using new, fully featured Japanese superbike (tcsh is like a classic chopper  it's not new and too fast, but it's pretty usable, and bash is like a hipster moped ). Moreover, it is even possible to use zsh to start bash scripts, just create zsh to bash symlink and use it with your bash scripts.


----------

