Skip to content

Instantly share code, notes, and snippets.

@fzero
Last active February 7, 2024 15:00
Show Gist options
  • Save fzero/4338767 to your computer and use it in GitHub Desktop.
Save fzero/4338767 to your computer and use it in GitHub Desktop.
Some tmux configurations, scripts and aliases I use.
# I prefer ctrl-a - helps when dealing with machines that only have Screen
unbind C-b
set -g prefix C-a
# Making windows purrty
set-window-option -g status-bg cyan
set-window-option -g status-fg black
set-window-option -g window-status-current-bg black
set-window-option -g window-status-current-fg white
set -g message-fg white
set -g message-bg black
set -g message-attr bright
# More options
set-window-option -g automatic-rename on
set -g default-terminal "screen-256color"
# Mouse options
set -g mouse on
bind -n WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -n WheelDownPane select-pane -t= \; send-keys -M
# enable wm window titles
set -g set-titles on
set -g set-titles-string "tmux.#I.#W"
# Act like Vim
setw -g mode-keys vi
# Vim-like pane navigation
bind C-h select-pane -L
bind h select-pane -L
bind C-j select-pane -D
bind j select-pane -D
bind C-k select-pane -U
bind k select-pane -U
bind C-l select-pane -R
bind l select-pane -R
# Vim-like splitting
bind s split-window -v
bind v split-window -h
# Vim-like copy
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
# UTF8 fixes - NOTE: They don't seem to work or do anything anymore
# set -g mouse-utf8 on
# setw -g utf8 on
# set -g status-utf8 on
# Some tmux-related shell aliases
# Attaches tmux to the last session; creates a new session if none exists.
alias t='tmux attach || tmux new-session'
# Attaches tmux to a session (example: ta portal)
alias ta='tmux attach -t'
# Creates a new session
alias tn='tmux new-session'
# Lists all ongoing sessions
alias tl='tmux list-sessions'
#!/bin/bash
SESSION='my_session'
# Example of tmux session setup script. This particular example starts several
# rails servers on a development machine. The session we create is named "my_session".
# Tests to see if the session already exists. If it does, just skip everything and reattach.
if [ "$(tmux list-sessions 2> /dev/null | grep -o $SESSION)" != "$SESSION" ]; then
tmux new-session -d -s $SESSION
# NOTE: We have to call bash (or $SHELL) after every command, or else the window will quit.
# This is not necessary if you don't run any commands.
tmux new-window -t $SESSION:1 -n '(Q)scheduler' "cd ~/Code/queue_service; VERBOSE=1 bundle exec rake resque:scheduler; $SHELL"
tmux new-window -t $SESSION:2 -n '(Q)worker' "cd ~/Code/queue_service; QUEUE=* VERBOSE=1 bundle exec rake resque:work; $SHELL"
tmux new-window -t $SESSION:3 -n '(D)keywords' "cd ~/Code/data-collection; bundle exec ruby run_keywords.rb; $SHELL"
tmux new-window -t $SESSION:4 -n '(D)follow' "cd ~/Code/data-collection; bundle exec ruby run_follow.rb; $SHELL"
tmux new-window -t $SESSION:5 -n '(R)app' "cd ~/Code/app; bundle exec rails server -p 3000; $SHELL"
# Gets rid of window 0, which is not accessible right away (hence sleep 1)
sleep 1
tmux unlink-window -k -t $SESSION:0
else
tmux attach -t $SESSION
fi
@huangruizhe
Copy link

Attaches tmux to the last session; creates a new session with a panel split into left and right

alias t='tmux attach || tmux new-session\; split-window -h'

@harryqt
Copy link

harryqt commented Mar 19, 2020

By default tmux ls is alias of tmux list-sessions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment