Description

The articles listed below introduced how to make use of Tmux in RHOST13 based contrail environment to expedite the login and troubleshooting process. So far, all Tmux keystroke commands are under default Tmux configuration. A "default" Tmux configuration means there are no customized changes to any Tmux default behavior. This is the case when we start our first Tmux session without any Tmux configuration file, such as `~/.tmux.conf`. Some commands by default involves more manual operations than one keystroke command, which makes it more difficult in day to day work. In this article, we'll introduce a group of recommended Tmux configurations we can use to customize the Tmux command, making the execution of all commands more consistent, and in some cases much simpler.

Related Articles:

Solution

Tmux can be configured with Tmux configuration commands in the default Tmux configuration file ~/.tmux.conf , which is a hidden file under the current home folder. Copy and paste the following text lines into this file.  This can be done easily by starting the ' cat ' command, pasting the text, and pressing 'ctr-d' in the end.

    (undercloud) [stack@hosta ~]$ cd
    cat > .tmux.conf
    set -g base-index 1
    set -g wrap-search off
    set -g prefix C-b
    set-option -g allow-rename off
    set -sg escape-time 10
    bind r source-file ~/.tmux.conf
    set-window-option -g aggressive-resize
    set-window-option -g automatic-rename on
    set-option -g set-titles on
    set-window-option -g xterm-keys on
    set -g default-terminal screen-256color
    set -g status-keys vi
    set -g history-limit 1000000
    setw -g monitor-activity on     #ping: enable activity alerts
    set -g visual-activity off
    set -g status-justify centre    #center the win list
    bind-key v split-window -h
    bind-key s split-window -v
    bind h select-pane -L
    bind j select-pane -D
    bind k select-pane -U
    bind l select-pane -R
    bind-key J command-prompt -p "join pane from:"  "join-pane -s '%%'"
    bind-key S command-prompt -p "send pane to:"  "join-pane -t '%%'"
    bind -n M-h select-pane -L
    bind -n M-j select-pane -D
    bind -n M-k select-pane -U
    bind -n M-l select-pane -R
    bind m \
        set synchronize-panes \;\
        display "Sync #{?synchronize-panes,ON,OFF}"
    bind-key C-b last-window
    bind-key -n C-S-Left swap-window -t -1
    bind-key -n C-S-Right swap-window -t +1


Note: This must be done before the first Tmux session in the host that is started.

Then start the first Tmux session as demonstrated in KB37199 - How to start a tmux session in Contrail [juniper.net] , but this time with customized Tmux commands:

    tmux new -s jtac

Table of comparison between Tmux default commands and customized commands:


    | function                        | default command                      | customized command |
    | split horizontally              | ctrl-b + "                           | ctrl-b + s         |
    | split vertically                | ctrl-b + %                           | ctrl-b + v         |
    | switch to the left pane         | ctrl-b + LEFT                        | ctrl-b + h         |
    | switch to the right pane        | ctrl-b + RIGHT                       | ctrl-b + l         |
    | switch to the upper pane        | ctrl-b + UP                          | ctrl-b + k         |
    | switch to the bottom pane       | ctrl-b + DOWN                        | ctrl-b + j         |
    | active pane synchronization     | ctrl-b + :setw synchronize-panes on  | ctrl-b + m         |
    | deactivate pane synchronization | ctrl-b + :setw synchronize-panes off | ctrl-b + m         |

The customized commands are more consistent and sometimes simpler. For the purpose of completeness, the following are other commands introduced in related Tmux articles. The configuration given in this article does not customize these commands, hence they remain the same.

    | function                        | default command
    | create a new window             | ctrl-b + c
    | switch to a window              | ctrl-b + WINDOW-NUMBER
    | detach current session          | ctrl-b + d
    | zoom in/out current pane        | ctrl-b + z
    | enter current pane buffer       | ctrl-b + [
    | scroll in pane buffer           | Down/Up/PageDown/PageUp