Friday, May 3, 2013

Install tmux on FreeBSD Tutorial Step by step

Install tmux on FreeBSD Tutorial Step by step

Install tmux
# cd /usr/ports/sysutils/tmux/ ; make install clean ; rehash

tmux options
# make showconfig
===> The following configuration options are available for tmux-1.5:
LIBEVENT2=on "Use libevent version 2"
LIBEVENT_STATIC=off "Build with static libevent"
BACKSPACE=on "Build with tty/keys patch"
===> Use 'make config' to modify these settings

Configuration Examples:
# ls /usr/local/share/examples/tmux

By default, tmux loads the system configuration file from /usr/local/etc/tmux.conf, if present, then looks for a user configuration file at ~/.tmux.conf.

Add following lines to your tmux.conf:
# vim /usr/local/etc/tmux.conf
or
# vim ~/.tmux.conf

### Note: key meaning
### C- means ctrl-, so C-x is ctrl-x.
### M- means meta (generally left-alt or escape)-, so M-x is left-alt-x.

### Set the prefix to ^A.
### Note: the default prefix is Ctrl-b.
unbind C-b
set -g prefix ^A
bind a send-prefix

### Set the maximum number of lines held in window history.
set -g history-limit 5000

### terminal 256 colors.
### As the tmux manual suggests: for tmux to work correctly, this must be set to "screen" or a derivative of it.
### Note: modify following line and set it to the terminal supported by your system (run cat /etc/termcap | egrep 'screen-256color|xterm-256color' to verify), and uncomment it.
###set -g default-terminal screen-256color
###set -g default-terminal xterm-256color

### Instructs tmux to expect UTF-8 sequences to appear in this window.
setw -g utf8 on

### Instruct tmux to treat top-bit-set characters in the status-left and status-right strings as UTF-8;
set -g status-utf8 on

### date format: hostname weekday month day, hour:minute
set -g status-right '#H %a %b %d, %H:%M'

### Set status line background colour.
set -g status-bg black

### Set status line foreground colour.
set -g status-fg yellow

### Set status line background colour for the currently active window.
setw -g window-status-current-bg magenta

### Set status line foreground colour for the currently active window.
setw -g window-status-current-fg white

### Reload tmux.conf configuration file
### Note: alternative way to reload the configuration file:
### Method 1: Run from command line: tmux source-file ~/.tmux.conf
### Method 2: In any tmux sessions: [prefix Ctrl-b] : source-file /usr/local/etc/tmux.conf
### Method 3: bind the source-file command with a key like following line, then you type: ctrl-b-r
bind r source-file /usr/local/etc/tmux.conf

### [START] vi- and vim-like bindings
### split windows like vim
### vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v
bind v split-window -h

### move around panes with hjkl, as one would in vim after pressing ctrl-w
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

### resize panes like vim
### feel free to change the "5" to however many lines you want to resize by, only
### one at a time can be slow
bind < resize-pane -L 5
bind > resize-pane -R 5
bind - resize-pane -D 5
bind + resize-pane -U 5

### bind : to command-prompt like vim
### this is the default in tmux already
bind : command-prompt

### vi-style controls for copy mode
setw -g mode-keys vi
### [END] vi- and vim-like bindings

Add following line to your ~/.cshrc:
# vim ~/.cshrc
### Note: modify following line and set it to the terminal supported by your system (run cat /etc/termcap | egrep 'screen-256color|xterm-256color' to verify), and uncomment it.
#setenv TERM screen-256color
#setenv TERM xterm-256color

Add following lines to your ~/.vimrc:
# vim ~/.vimrc
" To enable 256 colors in vim, put this your .vimrc before setting the colorscheme.
set t_Co=256

Use following script to test verify whether your terminal supports 256 colors:

a small perl script that outputs a grid of 256 colors in your console.

It should look like this:

To see a list of TERM values supported by the system:
# cat /etc/termcap

# cat /etc/termcap | egrep 'screen-256color|xterm-256color'

Determine the terminal capability interface:
# tput Co
8

# tput colors
115

# cap_mkdb

# setenv | grep TERM

# echo $TERM

# tmux

# tmux ls

# tmux a -d

# tmux attach -d -t 1

Move window, reorder window

The 'swap-window' command is closest to what you want. "Prefix :" (that is "Ctrl-B :" by default) brings you to the tmux-command prompt. There you enter 'swap-window -s 3 -t 1' to let window number 3 and window number 1 swap their positions.

To move the current window to the top, do 'swap-window -t 0' (if base-index is 0, as it is by default).

You can bind that command to a key (T for "top" for example) by adding

bind-key T swap-window -t 0

to your ~/.tmux.conf.


Note: if you see following error messages after run the tmux command:
csh: Cannot open /etc/termcap.
csh: using dumb terminal settings.

Make sure you set following line to the terminal supported by your system (run cat /etc/termcap | egrep 'screen-256color|xterm-256color' to verify) in your /usr/local/etc/tmux.conf:
set -g default-terminal screen-256color
or
set -g default-terminal xterm-256color


Other useful tool:
tmuxinator - Manage complex tmux sessions easily

screen and tmux

A comparison of the features (or more-so just a table of notes for accessing some of those features) for GNU screen and BSD-licensed tmux.
This document released for use under the PPL license available at http://code.dayid.org/ppl/ppl.txt
Want more information about tmux and screen? Check out This page also

The formatting here is simple enough to understand (I would hope). ^ means ctrl+, so ^x is ctrl+x. M- means meta (generally left-alt or escape)+, so M-x is left-alt+x
Action tmux screen
start a new session tmux OR
tmux new OR
tmux new-session
screen
re-attach a detached session tmux attach OR
tmux attach-session
screen -r
re-attach an attached session (detaching it from elsewhere) tmux attach -d OR
tmux attach-session -d OR
tmux a -d
screen -dr OR
screen -RD
re-attach an attached session (keeping it attached elsewhere) tmux attach OR
tmux attach-session
screen -x
detach from currently attached session ^b d OR
^b :detach
^a ^d OR
^a :detach
rename-window to newname ^b , <newname> OR
^b :rename-window <newname>
^a A <newname>
list windows ^b w ^a w
list windows in chooseable menu ^a "
go to window # ^b # ^a #
go to last-active window ^b l ^a l
go to next window ^b n ^a n
go to previous window ^b p ^a p
see keybindings ^b ? ^a ?
list sessions ^b s OR
tmux ls OR
tmux list-sessions
screen -ls
toggle visual bell ^a ^g
create another shell ^b c ^a c
exit current shell ^d ^d
split pane horizontally ^b "
split pane vertically ^b %
switch to another pane ^b o
kill the current pane ^b x OR (logout/^D)
close other panes except the current one ^b !
swap location of panes ^b ^o
show time ^b t
show numeric values of panes^b q


Reference:
http://gala4th.blogspot.com/2011/09/install-tmux-on-freebsd-tutorial-step.html
http://www.dayid.org/os/notes/tm.html

No comments: