Skip to content

Instantly share code, notes, and snippets.

@adamwespiser
Created January 6, 2020 02:46
Show Gist options
  • Save adamwespiser/2fee9aa38e6f7b0cc689aca3bd8b2599 to your computer and use it in GitHub Desktop.
Save adamwespiser/2fee9aa38e6f7b0cc689aca3bd8b2599 to your computer and use it in GitHub Desktop.
Tmux Config + Session Script
# set auto-reload of this config
bind r source-file ~/.tmux.conf \; display "Reloaded ~/.tmux.conf"
# set default tmux bash version ... move to fish?
set -g default-shell /usr/local/bin/bash
# set colors to 256
set -g default-terminal "screen-256color" # colors!
# start with window 1 (instead of 0)
set -g base-index 1
# start with pane 1
set -g pane-base-index 1
# mouse support on
set -g mouse on
# Pane colours :: set inactive/active window styles
set -g window-style 'fg=colour247,bg=colour236'
set -g window-active-style 'fg=colour250,bg=black'
# Pane Nav/management # splits by divider
bind | split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'
# new window as 'c'
bind c new-window -c '#{pane_current_path}'
# Use Alt-arrow keys without prefix key to switch panes
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
bind -n M-Tab select-pane -t +
bind -r Tab select-pane -t :.+
# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window
# copy to macOS clipboard
if -b 'command -v pbcopy > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | pbcopy"'
if -b 'command -v reattach-to-user-namespace > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | reattach-to-user-namespace pbcopy"'
# colours for messages
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
# Show reloaded message in bright white
set -g message-style fg=black
set -g message-style bg=default
set -g message-style bright
# status bar (Right side)
set -g status-right "#[fg=colour256]%d %b #[fg=colour256] %R"
set -g status-interval 60
#!/usr/local/bin/bash
tmux list-windows | cut -f 1 -d ':' | xargs -I{} tmux kill-window -t {}
tmux list-sessions
#!/usr/local/bin/bash
# https://blog.htbaa.com/news/tmux-scripting
# Assumes 1 index for panes and windows
SESSION=$USER
PROJECT="$HOME/projects/analytics"
tmux -2 new-session -d -s $SESSION
# Window 1 -- Monitor local system
tmux new-window -t $SESSION:1 -n 'Logs'
tmux split-window -h
tmux select-pane -t 1
tmux send-keys "top -o rsize -s 2" C-m
tmux select-pane -t 2
tmux send-keys "top -o cpu -s 2 -i 5" C-m
tmux split-window -v
tmux select-pane -t 3
tmux resize-pane -D 30
tmux send-keys "iostat -w 2 -n 16" C-m
# Window 2 -- Stack build local project
tmux new-window -t $SESSION:2 -n "stack"
tmux split-window -v
tmux select-pane -t 1
tmux send-keys 'cd $PROJECT && stack build --file-watch' C-m
tmux select-pane -t 2
tmux resize-pane -D 30
tmux send-keys 'cd $PROJECT && watch git status' C-m
# Window 3 -- Database connection
tmux new-window -t $SESSION:3 -n 'PostgreSQL' 'psql postgresql://analytics@localhost:5432/analytics'
# Window 4 - Terminal
tmux new-window -t $SESSION:4 -n 'edit'
tmux -2 attach-session -t $SESSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment