Gih's Blog

只言片语

tmux 终端模拟器

2011-06-03 by gihnius, tagged as shell

不知是不是用FreeBSD多的原因, 把用了多年的 screen 甩掉了, 在个人

电脑和服务器上都装上 tmux. 不过用tmux那么久也没感觉到跟screen有什么区别,速度两者差不多,就是tmux用内存比 screen 少. tmux也很稳定.好像tmux的配置并不比 screen的配置方法高明. 不管怎么样,用上了还是挺喜欢的!下面是我的配置:.screenrc:

setenv DISPLAY ':0.0'

escape ^Zz

caption always "%{=u} %{.W}%-w%{.W}%{=b G}%n %t%{-}%+w %L= %=%{..B} %H %{..Y} %m/%d %c%a "

bindkey -k k2 next
bindkey -k k1 prev

termcapinfo xterm*|rxvt|urxvt|mrxvt|*term* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
termcapinfo xterm* OL=5000
termcapinfo xterm|xterms|xs|rxvt 'ti@:te@'
termcapinfo xterm* 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'

bell "%c bell -> %n%f %t^G"
defscrollback 5000
msgwait 2
startup_message off
shell zsh
vbell_msg "$$$$"
vbell off

screen -t COM 0
screen -t ZSH 1
screen -t X 2
screen -t KSH 3 #ksh93 -i -l
select 1

#altscreen on
attrcolor b ".I"
defbce "on"
defutf8 "on"
nonblock "on" 
tmux配置.tmux.conf
unbind C-b
set -g prefix ^O
bind o send-prefix

# Statusbar properties.
set -g display-time 3000
set -g status-right "%m/%d %a %H:%M" 
set -g status-bg default
set -g status-fg yellow
set -g set-titles on
set -g bell-action none
set -g history-limit 5000
set -g base-index 1
setw -g automatic-rename off
set -g status-utf8 on
setw -g utf8 on
set-window-option -g window-status-current-attr bright,reverse
set-window-option -g window-status-current-bg black
set-window-option -g window-status-current-fg green
set-window-option -g automatic-rename off
set-window-option -g utf8 on

# Bind function keys.
bind -n F1 prev
bind -n F2 next
bind-key -n C-left prev
bind-key -n C-right next
## switch pane
bind-key -n M-left select-pane -L
bind-key -n M-right select-pane -R
bind-key -n M-up select-pane -U
bind-key -n M-down select-pane -D
bind-key -n C-\ split-window
bind-key -n M-\ split-window -h

bind-key -n C-F12 lock

### KEY map
# F1: prev window
# F2: next window
# Ctrl+\: split window V
# Alt+\: split window H
# Ctrl+F12: lock session
# Ctrl+Z+Left: resize pane left
# Ctrl+Z+Right: resize pane right
# Ctrl+Z+Up: resize pane up
# Ctrl+Z+Down: resize pane down
# Ctrl+Z then Left: switch to left pane
# Ctrl+Z then Right: switch to right pane
# Ctrl+Z then Up: switch to up pane
# Ctrl+Z then Down: switch to down pane
# Ctrl+Z then x: kill current pane or window 
在tmux里,我把 Prefix 按键绑定到 Ctrl+O 以免跟emacs冲突.tmux启动脚本:
#!/bin/sh
tmux has-session -t gih >/dev/null 2>&1
if [ $? -eq 0 ] ; then
    tmux -2 -u attach-session -t gih
else
    tmux new-session -d -s gih
    tmux new-window -d 
    tmux new-window -d
    tmux new-window -d
    tmux new-window -d
    tmux rename-window -t 1 SYS
    tmux rename-window -t 2 X
    tmux rename-window -t 3 NET
    tmux rename-window -t 4 LISP
    tmux rename-window -t 5 TOP
    tmux select-window -t 2
    tmux -2 -u attach-session -t gih
fi 
tmux配置说明就不说了.后来找到一个链接:介绍tmux的使用http://wiki.freebsdchina.org/software/t/tmux