Skip to content

Instantly share code, notes, and snippets.

@surskitt
Created April 3, 2019 22:28
Show Gist options
  • Save surskitt/85346bddf7c5d060db08b2b0323eda13 to your computer and use it in GitHub Desktop.
Save surskitt/85346bddf7c5d060db08b2b0323eda13 to your computer and use it in GitHub Desktop.
# make tmux display things in 256 colors
set -g default-terminal 'screen-256color'
set -g terminal-overrides ',xterm-256color:Tc'
set -as terminal-overrides ',xterm*:sitm=\E[3m'
# Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50
# Rebind prefix from ctrl+b to ctrl+a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
bind-key -n C-s send-prefix
# Unbind Ctrl+a, Ctrl+O
unbind C-o
# ctrl+a, s to select session
bind-key s choose-session
# ctrl+a, S to start a new session
bind-key S command-prompt -p ' new session:' "new-session -s %1 -n ''"
# ctrl+a, m to load a tmuxinator project
bind-key m command-prompt -p 'load tmuxinator project:' "new-window 'tmux switch %1 || tmuxinator start %1'"
# Create new window, with default "tmux" name (rename to hostname in shell)
bind-key c new-window -n ''
# ctrl+a, C to ssh to a server
bind C command-prompt -p ' ssh to:' "new-window -n %1 'ssh -X %1'"
# ctrl+Shift+Left/Right to swap windows
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
# pane navigation
bind -r h select-pane -L # move left
bind -r j select-pane -D # move down
bind -r k select-pane -U # move up
bind -r l select-pane -R # move right
bind > swap-pane -D # swap current pane with the next one
bind < swap-pane -U # swap current pane with the previous one
# is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
# | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
# bind-key -r h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
# bind-key -r j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
# bind-key -r k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
# bind-key -r l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
# bind-key -r o if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# window navigation
unbind n
bind C-h previous-window
bind C-l next-window
# session navigation
bind C-j switch-client -n
bind C-k switch-client -p
# Replace pane bindings with easier to remember ones
unbind % # Remove default binding since we’re replacing
unbind '"'
bind = split-window -h
bind - split-window -v
# Split window while ssh'ing
bind + command-prompt -p ' ssh to:' "split-window -h 'ssh -X %1'"
bind _ command-prompt -p ' ssh to:' "split-window -v 'ssh -X %1'"
# Toggle synchronise panes
bind @ setw synchronize-panes
# Switch between last two windows with ctrl+a, ctrl+a
bind-key C-a last-window
# shorten command delay
set -sg escape-time 1
# Start window numbers at 1
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# Reload tmux config with ctrl+a, r
bind r source-file ~/.tmux.conf \; display "Reloaded config file!"
set-window-option -g mode-keys vi
# # Use ctrl+a, Esc to enter copy mode instead of ctrl+a, [
unbind [
bind Escape copy-mode
# Setup 'v' to begin selection as in Vim
bind-key -Tcopy-mode-vi 'v' send -X begin-selection
# bind-key -t vi-copy 'y' copy-pipe "pbcopy"
bind-key -Tcopy-mode-vi 'y' send -X copy-selection
unbind p
bind p paste-buffer
bind g set status \; resize-pane -Z
# statusbar --------------------------------------------------------------
set-option -g allow-rename off
set-window-option -g automatic-rename off
# refresh the status bar every 5 seconds
set-option -g status-interval 5
# Turn mouse mode on
set -g mouse on
# Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
# (commented out because it disables cursor navigation in vim)
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"
# Scroll History
set -g history-limit 30000
# Set ability to capture on start and restore on exit window data when running an application
setw -g alternate-screen on
# visual notification of activity in other windows
setw -g monitor-activity off
set -g visual-activity off
set-option -g bell-action none
set -g visual-bell off
set -g set-titles on
# set -g set-titles-string "#T #F #W"
bind n set -g pane-border-status
set -g pane-border-format "#[bg=black,fg=#{?pane_active,white,#{?pane_synchronized,black,brightblack}}]  #P #T "
if-shell "[ -f ~/.tmux_local.conf ]" 'source ~/.tmux_local.conf'
PILOT_ROOT=$HOME/.vim/plugged/vim-tmux-pilot
source-file $PILOT_ROOT/pilot.tmux
# theme
set -g @prefix_highlight_fg black
set -g @prefix_highlight_bg brightcyan
set -g status on
set -g status-justify left
set -g status-bg black
set -g status-fg white
set -g status-attr none
set -g pane-border-bg black
set -g pane-border-fg black
set -g pane-active-border-bg black
set -g pane-active-border-fg brightblack
set -g display-panes-colour black
set -g display-panes-active-colour brightblack
setw -g clock-mode-colour cyan
set -g message-fg cyan
set -g message-bg brightblack
set -g message-command-bg cyan
set -g message-command-fg brightblack
set -g @prefix_highlight_output_prefix "#[bg=brightcyan,fg=black]#[nobold]#[noitalics]#[nounderscore]#[fg=brightcyan]#[bg=black]"
set -g @prefix_highlight_output_suffix ""
set -g @prefix_highlight_copy_mode_attr "bg=brightcyan,fg=black,bold"
set -g status-left "#[bg=black,fg=blue] ❐ #S "
set -g status-right "#{prefix_highlight}#[bg=black,fg=white]  %Y-%m-%d  %H:%M  #H "
set -g window-status-format "#[bg=black,fg=brightblack]  #I #W#{?window_zoomed_flag,,}"
set -g window-status-current-format "#[bg=black,fg=white]  #I #W#{?window_zoomed_flag,,}"
set -g window-status-separator ""
precmd() {
print
}
() {
# SEGMENT_SEPARATOR=$'\ue0b0'
SEGMENT_SEPARATOR=' '
FIRST=true
}
shrink_path () {
setopt localoptions
setopt rc_quotes null_glob
typeset -a tree expn
typeset result part dir=${PWD}
typeset -i i
[[ -d $dir ]] || return 0
if [[ $dir == $HOME ]] {
icon=''
} else {
icon=''
}
dir=${dir/$HOME/\~}
tree=(${(s:/:)dir})
(
unfunction chpwd 2> /dev/null
if [[ $tree[1] == \~* ]] {
cd ${~tree[1]}
result=$tree[1]
shift tree
} else {
cd /
}
for dir in $tree; {
if (( $#tree == 1 )) { result+="/$tree"; break; }
expn=(a b)
part=''
i=0
until [[ (( ${#expn} == 1 )) || $dir = $expn || $i -gt 99 ]] do
(( i++ ))
part+=$dir[$i]
expn=($(echo ${part}*(-/)))
# (( short )) && break
done
result+="/$part"
cd $dir
shift tree
}
echo $icon ${result:-/}
)
}
gitprompt() {
git status --branch --porcelain=v2 2>&1 | awk '
BEGIN {
fatal = 0;
oid = "";
head = "";
ahead = 0;
behind = 0;
untracked = 0;
unmerged = 0;
staged = 0;
unstaged = 0;
}
$1 == "fatal:" { fatal = 1; }
$2 == "branch.oid" { oid = $3; }
$2 == "branch.head" { head = $3; }
$2 == "branch.ab" { ahead = $3; behind = $4; }
$1 == "?" { ++untracked; }
$1 == "u" { ++unmerged; }
$1 == "1" || $1 == "2" {
split($2, arr, "");
if (arr[1] != ".") { ++staged; }
if (arr[2] != ".") { ++unstaged; }
}
END {
if (fatal == 1) { exit(1); }
printf "%s ", ""
if (head == "(detached)") {
printf ":%s ", substr(oid, 0, 7);
} else {
printf "%s ", head;
}
if (behind < 0) { printf "↓%d", behind * -1; }
if (ahead > 0) { printf "↑%d", ahead; }
if (unmerged > 0) { printf "✖%d", unmerged; }
if (staged > 0) { printf "●%d", staged; }
if (unstaged > 0) { printf "%d", unstaged; }
if (untracked > 0) { printf "…%d", untracked; }
if (unmerged == 0 && staged == 0 && unstaged == 0 && untracked == 0) { printf "✔" }
}
'
}
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $FIRST != true && $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
# Context: user@hostname (who am I and where am I)
prompt_context() {
if $HOST_IN_PROMPT && [[ -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$HOST"
FIRST=false
fi
}
# Dir: current working directory
prompt_dir() {
# prompt_segment blue default '%~'
prompt_segment black blue '$(shrink_path -l -t)'
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path ]]; then
prompt_segment black yellow " $(basename $virtualenv_path)"
FIRST=false
fi
}
prompt_git() {
# local gp=$(gitprompt)
# [[ ! -z "$gp" ]] && {
# prompt_segment red black " ${gp}"
# FIRST=false
# }
prompt_segment black red '$(gitprompt)'
FIRST=false
}
prompt_newline() {
print
}
## Main prompt
build_prompt() {
prompt_context
prompt_virtualenv
prompt_git
prompt_dir
prompt_end
}
build_rprompt() {
}
MODE_INDICATOR="NORMAL"
setopt PROMPT_SUBST
PROMPT="%{%f%b%k%}$(build_prompt)"
RPROMPT="$(build_rprompt)"
" =============================================================================
" Filename: autoload/lightline/colorscheme/wal.vim
" Author: Dylan Araps
" License: MIT License
" Last Change: 2017/10/28 12:21:04.
" =============================================================================
let s:black = [ '', 232 ]
let s:gray = [ '', 0 ]
let s:lgray = [ '', 8 ]
let s:white = [ '', 7 ]
let s:darkblue = [ '', 4 ]
let s:cyan = [ '', 6 ]
let s:green = [ '', 2 ]
let s:orange = [ '', 11 ]
let s:purple = [ '', 5 ]
let s:red = [ '', 1 ]
let s:yellow = [ '', 3 ]
let s:p = {'normal': {}, 'inactive': {}, 'insert': {}, 'replace': {}, 'visual': {}, 'tabline': {}}
let s:p.normal.left = [ [ s:darkblue, s:gray ], [ s:white, s:gray ] ]
let s:p.normal.middle = [ [ s:white, s:gray ] ]
let s:p.normal.right = [ [ s:green, s:gray ], [ s:cyan, s:gray ] ]
let s:p.normal.warning = [ [ s:yellow, s:gray ] ]
let s:p.normal.error = [ [ s:red, s:gray ] ]
let s:p.inactive.left = [ [ s:cyan, s:gray ], [ s:white, s:gray ] ]
let s:p.inactive.middle = [ [ s:white, s:gray ] ]
let s:p.inactive.right = [ [ s:black, s:gray ], [ s:white, s:gray ] ]
let s:p.insert.left = [ [ s:green, s:gray ], [ s:white, s:gray ] ]
let s:p.replace.left = [ [ s:purple, s:gray ], [ s:white, s:gray ] ]
let s:p.visual.left = [ [ s:orange, s:gray ], [ s:white, s:gray ] ]
let s:p.tabline.left = [ [ s:lgray, s:gray ] ]
let s:p.tabline.middle = [ [ s:white, s:gray ] ]
" let s:p.tabline.right = copy(s:p.normal.right)
let s:p.tabline.right = [ [ s:white, s:gray ] ]
let s:p.tabline.tabsel = [ [ s:cyan, s:gray ] ]
let g:lightline#colorscheme#wal#palette = lightline#colorscheme#flatten(s:p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment