Basti's Scratchpad on the Internet

tmux Configuration

This is a dump of all tmux related configuration and scripts so I can edit them in one place and tangle from a single file.

tmux configuration

Start windows and panes at 1, not 0,

set -g base-index 1
set -g pane-base-index 1

Replace C-b with \,

unbind C-b 
set -g prefix '\'
bind-key '\' send-prefix
set-window-option -g xterm-keys on

Setup key bindings,

bind t source-file ~/.tmux-over-ssh.conf
bind k confirm kill-window
bind K confirm kill-server

bind tab last-window

# window movement / renumbering like in screen's :number
bind-key m command-prompt -p "move window to:"  "swap-window -t '%%'"

Enable UTF-8,

setw -g utf8 on
set -g status-utf8 on
setw -g window-status-current-format "|#I:#W|"

Makes using the scroll wheel automatically switch to copy mode and scroll back the tmux scrollback buffer.

setw -g mode-mouse on

Status bar,

set-option -g  status-interval 1
set-option -g status-right-length 120
set -g status-right '#(~/.tmux-monitor-scripts/cpu.sh)#(~/.tmux-monitor-scripts/cpu_avg_temp.sh)#(~/.tmux-monitor-scripts/disk.sh)#(~/.tmux-monitor-scripts/netspeed eth0)#(~/.tmux-monitor-scripts/battery.sh)#(date +"%a %b %_d %H:%M") | #(hostname)'

Create a new window, swtich to home directory and type tmux-ssh,

neww -n tmux-ssh
send-keys -t tmux-ssh "cd ~/" C-m
send-keys -t tmux-ssh "tmux-ssh "

Solarized theme,

# default statusbar colors
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default

# default window title colors
set-window-option -g window-status-fg colour244 #base0
set-window-option -g window-status-bg default
#set-window-option -g window-status-attr dim

# active window title colors
set-window-option -g window-status-current-fg colour166 #orange
set-window-option -g window-status-current-bg default
#set-window-option -g window-status-current-attr bright

# pane border
set-option -g pane-border-fg colour235 #base02
set-option -g pane-active-border-fg colour240 #base01

# message text
set-option -g message-bg colour235 #base02
set-option -g message-fg colour166 #orange

# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange

# clock
set-window-option -g clock-mode-colour colour64 #green

System Activity Scripts

Battery status,

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 temperature,

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

CPU load and free memory,

#!/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 "C: %.f%% M: %.f%% | " $CPU $FREE_MEM
        ;;
esac

DISK I/O

#!/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

Network I/O

#!/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
Other posts
comments powered by Disqus