Skip to content

Instantly share code, notes, and snippets.

@vaughany
Last active July 16, 2024 23:03
Show Gist options
  • Save vaughany/483324b983ac51281ef63bb672f6c1ed to your computer and use it in GitHub Desktop.
Save vaughany/483324b983ac51281ef63bb672f6c1ed to your computer and use it in GitHub Desktop.
A shell script to open tmux with a selection of windows and panes.
# Remap prefix from 'C-b' to 'C-a'.
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Reload config file.
bind-key r source-file ~/.tmux.conf\; display ' Reloaded tmux config.'
# Split panes using | and -.
bind-key | split-window -h -c '#{pane_current_path}'
bind-key - split-window -v -c '#{pane_current_path}'
unbind '"'
unbind %
# 0 is too far from Ctrl-a.
set -g base-index 1
# 1-indexed panes to match the windows.
setw -g pane-base-index 1
# Look nice.
set -g default-terminal screen-256color
# MOAR HISTORY BUFFER!
setw -g history-limit 1000000
# Clock settings.
setw -g clock-mode-colour white
setw -g clock-mode-style 24
# Switch windows using Alt-PgDn and Up without prefix. S-Left and S-Right still work.
bind-key -n M-PgDn next-window
bind-key -n M-PgUp previous-window
# Switch panes using Alt-arrow without prefix.
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
# Resize panes.
bind-key -r C-Left resize-pane -L 5
bind-key -r C-Right resize-pane -R 5
bind-key -r C-Up resize-pane -U 2
bind-key -r C-Down resize-pane -D 2
#unbind 'M-Left'
#unbind 'M-Right'
#unbind 'M-Up'
#unbind 'M-Down'
# Enable mouse mode (tmux 2.1 and above).
set -g mouse on
set -g pane-border-style fg=blue,bg=default
set -g pane-active-border-style fg=green,bg=default
set -g pane-border-format '#[align=right]#{?pane_active,#[fg=white bg=colour22],#[fg=default]} #{window_name}:#{pane_index} #{pane_current_command} #{pane_current_path} #[default]'
set -g pane-border-status top
# Status bar.
set -g status 2 # Can be 2 (lines height) in some versions of tmux.
set -g status-position bottom
set -g status-interval 30
set -g status-justify left
set -g status-left-length 50
set -g status-right-length 100
set -g status-fg colour249
set -g status-bg colour238
set -g status-left '#H #{?client_prefix,#[bg=colour10 fg=colour0] Ctrl #[default] ,}'
set -g status-right '#(uptime -p | sed "s/ years\?,/y/;s/ weeks\?,/w/;s/ days\?,/d/;s/ hours\?,/h/;s/ minutes\?/m/"), #[fg=colour255]#(hostname -I | sed "s/ / \/ /;s/ *$//g"),#[default] #(cut -d " " -f 1-3 /proc/loadavg), #[fg=colour255]%H:%M:%S'
# #set -g window-status-format
# set -g window-status-fg default
# set -g window-status-bg default
# #set -g window-status-attr dim
# #set -g window-status-current-format
# set -g window-status-current-bg colour252
# set -g window-status-current-fg colour0
# set -g window-status-current-attr bright
# Shift + arrow key to move between windows.
#bind-key -n S-Left previous-window
#bind-key -n S-Right next-window
bind-key -n S-Left previous-window
bind-key -n S-Right next-window
# Repeat time increase.
set -g repeat-time 1000
# Messages
set -g message-style bg=colour3,fg=colour0
set -g display-time 1000
# Sync panes
bind-key s setw synchronize-panes
setw -g window-status-current-format '#[bg=colour244 fg=white]#{?pane_synchronized,#[bg=yellow],} #I:#W '
setw -g window-status-format '#{?pane_synchronized,#[bg=yellow fg=black],} #I:#W '
#!/bin/bash
# Works with tmux 2.6 on Ubuntu 18.04. Your mileage may vary.
# 'send-keys' exists only to show/prove what's going where: the space prevents command history retention
# and the hashtag indicates a comment so bash doesn't try to run it.
session="testing"
# Removed: seems unnecessary.
# tmux start-server
# Create new session, and extra windows.
tmux new-session -d -s $session -n Window\ 1
tmux send-keys " # screen 1, pane 1" C-m
# Split window into two, horizontally: 67%/33% of current window.
tmux split-window -h -p 33
tmux send-keys " # screen 1, pane 2" C-m
# Split (new) window into two, vertically: 33%/67% of current window.
tmux split-window -v -p 67
tmux send-keys " # screen 1, pane 3" C-m
# Split (new new) window into two, vertically: 50%/50% of current window.
tmux split-window -v -p 50
tmux send-keys " # screen 1, pane 4" C-m
# Select pane 0.
tmux select-pane -t 1
tmux send-keys " # back here again" C-m
# Split window into two, vertically: 50%/50% of current window.
tmux split-window -v -p 50
tmux send-keys " # screen 1, pane 5" C-m
# All the other panes are now renumbered!!
# Focus the top-left pane. For sanity.
tmux select-pane -t 1
# A second whole window!
tmux new-window -t $session:2 -n Window\ 2
tmux send-keys " # screen 2, pane 1" C-m
tmux split-window -h -p 50
tmux send-keys " # screen 2, pane 2" C-m
tmux select-pane -t 0
# A THIRD whole window!
tmux new-window -t $session:3 -n Window\ 3
tmux send-keys " # screen 3, pane 1" C-m
tmux split-window -v -p 50
tmux send-keys " # screen 3, pane 2" C-m
tmux select-pane -t 0
# Select the second window, then the first window (so that the second window is the 'next' one).
tmux select-window -t $session:2
tmux select-window -t $session:1
# Make it so. This must be the very last command.
tmux attach-session -t $session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment