Skip to content

Instantly share code, notes, and snippets.

@JeremyOttley
Created November 15, 2017 14:01
Show Gist options
  • Save JeremyOttley/054122459a78adbc9e140aad088e3a42 to your computer and use it in GitHub Desktop.
Save JeremyOttley/054122459a78adbc9e140aad088e3a42 to your computer and use it in GitHub Desktop.
Tmux Configuration
##
## Basic Options
##
# UTF-8
set -g utf8 on
set -g status-utf8 on
# Mouse
set -g mouse-select-pane off
set -g mode-mouse off
set -g mouse-select-window off
set -g mouse-resize-pane off
# Shut up!
set -g bell-action none
set -g bell-on-alert off
set quiet off
# Fix terminal name issues
set -s escape-time 1
# Enable status bar
bind-key b set status
##
## Copy mode
##
unbind [
bind Escape copy-mode
setw -g mode-keys vi
unbind p
bind p paste-buffer
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
##
## Key bindings
##
unbind b
set -g prefix C-k
# Reload configuration
bind r source-file ~/.tmux.conf
# Panel splites and selection
unbind %
bind g split-window -h
unbind '"'
bind v split-window -v
unbind o
bind-key -n C-g last-window
bind-key -n C-b previous-window
bind-key -n C-n next-window
bind n next-window
bind b previous-window
# Move around panes with hjkl, as one would in vim after pressing ctrl-w
unbind Left
unbind Right
unbind Up
unbind Down
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize
bind H resize-pane -L 5
bind J resize-pane -D 5
bind K resize-pane -U 5
bind L resize-pane -R 5
# Kill
bind q kill-window
bind Q kill-session
##
## Appearance
##
# Status bar
set -g status-position bottom
set -g status-interval 4
set -g status-left ''
set -g status-right ''
set -g status-justify centre # center align window list
setw -g status-bg default
setw -g window-status-current-bg default
setw -g window-status-current-fg default
setw -g window-status-bg default
setw -g window-status-fg white
setw -g window-status-format '#[bg=black]#[fg=black,bold] #I #[bg=default] #[fg=black]#W '
setw -g window-status-current-format '#[fg=white]#[bg=cyan] #I #[fg=cyan]#[bg=default] #W '
# Panel borders
set -g pane-active-border-fg cyan
set -g pane-active-border-bg default
set -g pane-border-fg black
set -g pane-border-bg default
# Message text
set-option -g message-bg default
set-option -g message-fg default
#!/bin/bash
# ------------------------------------------------------------------------------
#
# Modified TMUX start script from:
# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# Store it to `~/bin/tmx` and issue `chmod +x`.
#
# ------------------------------------------------------------------------------
function check_session() {
local postfix="$1"
shift
"${tmux[@]}" -L "session-$postfix" list-sessions -F "#S" 2>/dev/null | grep -q "$base_session-$postfix"
}
tmux=( "tmux" )
base_session="$USER"
if [[ "$XDG_SESSION_ID" ]] && check_session "$XDG_SESSION_ID"; then
tmux+=( "-L" "session-$XDG_SESSION_ID" )
base_session+="-$XDG_SESSION_ID"
fi
# ------------------------------------------------------------------------------
new_session="${base_session}-$$"
# Count tmux sessions (1 master + N slaves).
# If there are no slave sessions, do not create new windows.
if (( $("${tmux[@]}" ls | wc -l) > 1 )); then
NEW_WINDOW_COMMAND=("new-window" "$*" ";")
fi
# Create a new session (without attaching it) and link to base session to share windows
# Attach to the new session & kill it once orphaned
exec "${tmux[@]}" new-session -d -t "$base_session" -s "$new_session" \; \
attach-session -t "$new_session" \; \
"${NEW_WINDOW_COMMAND[@]}" \
set-option destroy-unattached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment