I have been using tmux for a while now so I could have
tabs and
split windows when I remote SSH into my machines for work... and I love it!
http://tmux.sourceforge.net/
Here's what it look likes:
I thought it would be nice if people wanted to share their setups and scripts.
Here's my ~/.tmux.conf file:
Code:
# ---------------------
# Configuration
# ---------------------
# use UTF8 unicode
set -g utf8
set-window-option -g utf8 on
set -g status-utf8 on
# make tmux display things in 256 colors
# local .bashrc needs to have: export TERM=xterm-256color
set -g default-terminal "xterm-256color"
# set scrollback history to 10000 (10k)
set -g history-limit 10000
# shorten command delay
set -sg escape-time 1
# visual notification of activity in other windows
setw -g monitor-activity on
set -g visual-activity on
# set window and pane index to 1 (0 by default)
set-option -g base-index 1
setw -g pane-base-index 1
# ---------------------
# New Keyboard Bindings
# ---------------------
# set Ctrl-a as the default prefix key combination
# and unbind C-b to free it up
set -g prefix C-a
unbind C-b
# use send-prefix to pass C-a through to application
bind C-a send-prefix
# rebind clear screen with Ctrl-l
bind C-l send-keys 'C-l'
# reload ~/.tmux.conf using PREFIX r
bind r source-file ~/.tmux.conf \; display "Config reloaded"
# use PREFIX | to split window horizontally and PREFIX - to split vertically
bind \ split-window -h
bind | split-window -h
bind - split-window -v
bind _ split-window -v
# make the current window the first window
bind T swap-window -t 1
# setup tab to switch windows
bind tab last-window
# map pane switching with ALT+Arrow keys
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
# toggle zoom
bind b break-pane
# join windows
bind-key j command-prompt -p "join pane from:" "join-pane -s '%%'"
bind-key s command-prompt -p "send pane to:" "join-pane -t '%%'"
# toggle mouse on
unbind-key -n F8
bind-key -n F8 \
set -g mode-mouse on \;\
set -g mouse-resize-pane on \;\
set -g mouse-select-pane on \;\
set -g mouse-select-window on \;\
display 'Mouse: ON'
# 9/16/2014 5:04:08 PMtoggle mouse off
unbind-key -n F9
bind-key -n F9 \
set -g mode-mouse off \;\
set -g mouse-resize-pane off \;\
set -g mouse-select-pane off \;\
set -g mouse-select-window off \;\
display 'Mouse: OFF'
# ---------------------
# Mouse
# ---------------------
# switch panes by using the mouse (turns off the ability to select text for local clipboard copy!)
# setw -g mouse-utf8 on
# set -g mode-mouse on
# setw -g mode-mouse on
# set -g terminal-overrides 'xterm*:smcup@:rmcup@'
# set-option -g mouse-select-pane on
# setw -g mouse-select-window on
# setw -g mouse-resize-pane on
# OR explicitly disable mouse control
setw -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off
# ---------------------
# Copy & Paste
# ---------------------
# setup reattach-to-user-namespace for copy and paste
# set-option -g default-command "reattach-to-user-namespace -l $SHELL"
# set-window-option -g automatic-rename on
# ---------------------
# VIM
# ---------------------
# use vim keybindings in copy mode
# setw -g mode-keys vi
# setup 'v' to begin selection as in Vim
# bind-key -t vi-copy v begin-selection
# bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
# update default binding of 'Enter' to also use copy-pipe
# unbind -t vi-copy Enter
# bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
# bind y run 'tmux save-buffer - | reattach-to-user-namespace pbcopy '
# bind C-y run 'tmux save-buffer - | reattach-to-user-namespace pbcopy '
# set copy-mode settings
# bind [ copy-mode
# bind -t vi-copy v begin-selection
# bind -t vi-copy y copy-selection
# bind -t vi-copy V rectangle-toggle
# bind ] paste-buffer
# map Vi movement keys as pane movement keys
# bind h select-pane -L
# bind j select-pane -D
# bind k select-pane -U
# bind l select-pane -R
# and use C-h and C-l to cycle thru panes
# bind -r C-h select-window -t :-
# bind -r C-l select-window -t :+
# resize panes using PREFIX H, J, K, L
# bind H resize-pane -L 5
# bind J resize-pane -D 5
# bind K resize-pane -U 5
# bind L resize-pane -R 5
# ----------------------
# Pane Highlighting
# ----------------------
# Options: black red yellow green blue magenta cyan white
# or write "colour\d+", e.g. "colour5" or "colour170"
# set pane colors - hilight the active pane
# inactive border
set-option -g pane-border-fg colour235 # dark gray
set-option -g pane-border-bg colour233 # super dark gray
# active border
set-option -g pane-active-border-fg white # white
set-option -g pane-active-border-bg colour233 # super dark gray
# ----------------------
# Status Bar
# -----------------------
set-option -g status on # turn the status bar on
set -g status-interval 1 # set update frequencey (default 15 seconds)
set -g status-justify centre # center window list for clarity
# set-option -g status-position top # position the status bar at top of screen
# set color for status bar
# set-option -g status-attr dim
set-option -g status-bg colour234
set-option -g status-fg white
# status left options
set-option -g status-left-length 80
set-option -g status-left "#[fg=colour240](#[bg=default,fg=colour255]#H#[fg=colour240])-(#[bg=default,fg=colour39]#S#[fg=colour240])"
# window list options
setw -g automatic-rename on
set-window-option -g window-status-format '#[fg=colour51,dim]#I#[fg=colour32]:#[fg=colour253]#W#[fg=colour253,dim]#F'
set-window-option -g window-status-current-format '#[bg=colour25,fg=colour51,bold]#I#[bg=colour25,fg=colour32]:#[fg=colour230]#W#[fg=dim]#F'
set -g base-index 1
# status right options
set-option -g status-right-length 80
set -g status-right "#[fg=colour240](#[fg=colour39]%a %b %-m %Y#[fg=colour240])-(#[fg=colour255]%-I:%M:%S%P#[fg=colour240])"
# ----------------------
# Scripts
# -----------------------
# bind h source-file ~/.tmux/yourfile
I have most of the VIM lines commented out at the moment, but if you use VIM, just put them back.
This makes CTRL-A the modifier and makes F8 and F9 turn the mouse on and off (the only two function keys that work in all terminals in all operating systems).
Also, you'll want to add this to your ~/.bashrc file:
Code:
# Make sure 256 color terminals are enabled
export TERM=xterm-256color
And, optionally, you can add this code into your prompt (export PROMPT_COMMAND) to change the tab names automatically to the folder you are in:
Code:
# If we are in tmux, change the window name to our current path
# If tmux is installed
if [ "$(type -t tmux)" = "file" ]; then
# If we are in tmux
if [ ! -z "$TMUX" ]; then
tmux rename-window ${PWD//*\//};
fi
fi
I also have some nifty scripts in my ~/.tmux directory that I'm not using at the moment but here they are:
battery.sh
Code:
if [ -d /sys/class/power_supply/BAT0 ];
then
now=`cat /sys/class/power_supply/BAT0/energy_now`
full=`cat /sys/class/power_supply/BAT0/energy_full`
out=`echo $now/$full*100 | bc -l | cut -c 1-5`
printf "%.f%% | " $out
else
echo ""
fi
cpu.sh
Code:
#!/bin/bash
case "$OSTYPE" in
linux-gnu)
CPU=`eval $(awk '/^cpu /{print "previdle=" $5 "; prevtotal=" $2+$3+$4+$5 }' /proc/stat); sleep 0.4; eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat); intervaltotal=$((total-${prevtotal:-0})); echo "$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))"`
FREE_MEM=`free | awk '/buffers\/cache/{print (100 - ($4/($3+$4) * 100.0));}'`
printf "CPU:%.f%% Mem:%.f%%" $CPU $FREE_MEM
;;
esac
cpu_avg_temp.sh
Code:
case "$OSTYPE" in
linux-gnu)
if which sensors > /dev/null; then
sensors | grep Core | awk '{print $3;}' | grep -oEi '[0-9]+.[0-9]+' | awk '{total+=$1; count+=1} END {print total/count,"C"}'
else
""
fi
;;
esac
disk.sh
Code:
#!/bin/bash
case "$OSTYPE" in
linux-gnu)
io_line_count=`iostat -d -x -m | wc -l` ;
iostat -d -x -m 1 2 -z | tail -n +$io_line_count | grep -e "^sd[a-z].*" | awk 'BEGIN{rsum=0; wsum=0}{ rsum+=$6; wsum+=$7} END {print "IO:" rsum " " wsum ""}'
;;
esac
net_connections.sh
Code:
#!/bin/bash
awk 'END {print NR}' /proc/net/tcp
net_speed.sh
Code:
#!/bin/bash
case "$OSTYPE" in
linux-gnu)
if [ -z "$1" ]; then
echo
echo usage: $0 network-interface
echo
echo e.g. $0 eth0
echo
exit
fi
IF=$1
R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep 1
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`
printf "%s:%d %d " $1 $RKBPS $TKBPS
;;
esac
Lastly, when you want to load tmux as your "shell" or want to make an alias to load it, use this:
Code:
tmux a -t Session || tmux new -s Session
That will connect to the session if it's created or create it if it doesn't exist yet.
For more information on tmux, this is a great tutorial:
http://lukaszwrobel.pl/blog/tmux-tut...windows-easily