Make tmux ssh sensitive

This commit is contained in:
Henrik Lissner 2015-12-22 03:49:27 -05:00
parent fa52a0d329
commit 1e36b0a2f8
3 changed files with 104 additions and 48 deletions

View file

@ -1,4 +1,7 @@
## Behavior ###############
####
run-shell "~/.dotfiles/tmux/conf.sh"
# utf-8
set -g utf8 on
set -g status-utf8 on
@ -15,55 +18,29 @@ set -g escape-time 0
# tmux messages are displayed for 4 seconds
set -g display-time 2000
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize off
# go zsh, go
set -g default-shell $SHELL
# a mouse
# setw -g mouse-utf8 on
setw -g mouse on
# fix mouse scrolling: enter copy mode on scroll-up, exits it when scrolled to bottom
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"
# set -g visual-activity off
setw -g monitor-activity on
# focus events enabled for terminals that support them
set -g focus-events on
# increase scrollback buffer size
set -g history-limit 10000
## Key bindings ###########
# Remap the key prefix
set -g prefix ^c
set -g prefix2 ^f
unbind C-b
# Restore sigterm C-c
bind C-c send-prefix
# set vi keys
setw -g mode-keys vi
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-pipe "reattach-to-user-namespace pbcopy"
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
## Pane management #####
# Better splitting keybinds
# Saner splitting commands
unbind %
unbind '"'
bind s split-window -v
bind v split-window -h
bind s split-window -c "#{pane_current_path}" -v
bind v split-window -c "#{pane_current_path}" -h
bind c new-window -c "#{pane_current_path}"
# break pane into a window
bind = break-pane
@ -85,16 +62,6 @@ bind C-w last-pane
bind C-n next-window
bind C-p previous-window
bind -n C-1 select-window -t :1
bind -n C-2 select-window -t :2
bind -n C-3 select-window -t :3
bind -n C-4 select-window -t :4
bind -n C-5 select-window -t :5
bind -n C-6 select-window -t :6
bind -n C-7 select-window -t :7
bind -n C-8 select-window -t :8
bind -n C-9 select-window -t :9
# Pane resizing
bind C-h resize-pane -L 6
bind C-j resize-pane -D 6
@ -113,7 +80,6 @@ bind L run '~/.dotfiles/tmux/swap-pane.rb right'
bind M run '~/.dotfiles/tmux/swap-pane.rb master'
bind o resize-pane -Z
bind P run-shell '~/.dotfiles/tmux/select-pane.sh'
bind S choose-session
bind W choose-window
bind / choose-session
@ -122,7 +88,7 @@ bind . choose-window
bind n run-shell 'TMUX= tmux new-session -t "$(basename \"$PWD\")" -d \; switch-client -t "$(basename \"$PWD\")"'
bind N run-shell 'TMUX= tmux new-session -t "$(tmux display-message -p #S)" -s "$(tmux display-message -p #S-clone)" -d \; switch-client -n \; display-message "session #S cloned"'
bind = select-layout tiled
# bind = select-layout tiled
bind | select-layout even-horizontal
bind _ select-layout even-vertical
@ -136,8 +102,6 @@ bind X kill-window
bind q kill-session
bind Q kill-server
# quick view of processes
bind '~' split-window "exec top"
## Looks ########################
set -g set-titles on
@ -156,14 +120,14 @@ setw -g window-status-activity-fg white
set -g pane-active-border-fg yellow
set -g pane-border-fg colour238
set -g status-bg colour237
set -g status-fg white
set -g status-interval 60
set -g status-justify left
set -g status-right-length 100
set -g status-left-length 80
set -g status-left '#[fg=white] #S #[fg=yellow]'
set -g status-right "#[fg=colour242]<#[fg=colour248]< #(tmux-mem-cpu-load -i 5) < #[fg=yellow]#(dig +short myip.opendns.com @208.67.222.222) #[bg=yellow]#[fg=black] #(hostname) "
set -g status-left "#{prefix_highlight}#(~/.dotfiles/tmux/conf-status.sh left) "
set -g status-right "#(~/.dotfiles/tmux/conf-status.sh right) "
# set -g status-right "#[fg=colour242]<#[fg=colour248]< #(tmux-mem-cpu-load -i 5) < #[fg=yellow]#(dig +short myip.opendns.com @208.67.222.222) #[bg=yellow]#[fg=black] #(hostname) "
set -g window-status-format " #I #W:#T "
set -g window-status-current-format " ⮀ #W:#T "

36
tmux/conf-status.sh Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
color() { echo "#[$1=$2]"; }
HOSTNAME=$(hostname)
RESET='#[default]'
if [[ "$1" == "left" ]]
then
FG=white
[[ -n "$SSH_CONNECTION" ]] && FG=black
STATUS=$(color fg $FG)' '$(tmux display-message -p '#S')
else
if [[ -z "$SSH_CONNECTION" ]]; then
DELIM=$(color fg yellow)
SYSINFO=$(color fg colour246)
IP=$(color fg white)
HOST=$(color bg yellow)$(color fg black)
else
DELIM=$(color fg black)
SYSINFO=$(color fg black)
IP=$(color fg black)
HOST=$(color bg black)$(color fg yellow)
fi
STATUS=$DELIM'<< '$RESET
STATUS+=$SYSINFO$(tmux-mem-cpu-load -i 5)$RESET
STATUS+=$DELIM' < '$RESET
STATUS+=$IP
STATUS+=$(dig +short myip.opendns.com @208.67.222.222)
STATUS+=' '$RESET$HOST' '
STATUS+=$HOSTNAME
fi
echo $STATUS

56
tmux/conf.sh Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env sh
TMUX_VERSION=$(tmux -V | awk '{ print $2 }')
## Mouse #########
if (( $(echo "$TMUX_VERSION >= 2.1" | bc) )); then
# setw -g mouse-utf8 on
tmux setw -g mouse on
# fix mouse scrolling: enter copy mode on scroll-up, exits it when scrolled to bottom
tmux bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"
else
tmux setw -g mode-mouse
tmux set -g mouse-resize-pane on
tmux set -g mouse-select-pane on
tmux set -g mouse-select-window on
fi
# Fix clipboard access on osx
if [[ "$OSTYPE" == darwin* ]]; then
tmux unbind p
tmux bind p paste-buffer
tmux bind-key -t vi-copy 'v' begin-selection
tmux bind-key -t vi-copy 'y' copy-pipe "reattach-to-user-namespace pbcopy"
tmux unbind -t vi-copy Enter
tmux bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
tmux setw -g aggressive-resize off
# increase scrollback buffer size
tmux set -g history-limit 10000
else
tmux setw -g aggressive-resize on
# increase scrollback buffer size
tmux set -g history-limit 5000
fi
# If in ssh, use default C-b prefix
if [[ -z "$SSH_CONNECTON" ]]
then
# Remap the key prefix
tmux set -g prefix ^c
tmux unbind C-b
# Restore sigterm C-c
tmux bind C-c send-prefix
tmux set -g status-bg colour237
tmux set -g status-fg white
else
tmux set -g status-bg yellow
tmux set -g status-fg black
fi