-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-setup
executable file
·230 lines (202 loc) · 6 KB
/
tmux-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/sh
# usage: @@name@@ [-h|--help|-?|-c] [arg ...]
#
# Execute this file to load up the tmux paste buffer with
# commands to populate dotfiles. Use `-c` to omit the commands
# and just load the content into the paste buffer. (This is not
# intended to be precise, and some commands leave a bit of cruft
# that may need to be edited.)
# Unset TMUX if you really want to just execute the script.
# Pass args such as bashrc or bash_profile to load just one file.
# Use -h for help and a list of available files.
if (return 0 2>/dev/null); then
# I used to source this file, and old habits die hard.
echo 'Do not source this. Just execute it!' >&2
return 1
fi
if test -z "$TMUX"; then
echo 'This loads a tmux buffer. Do not run outside of tmux!!' >&2
exit 1
fi
# Parse the file to find available files to load
available=$(
sed -e '1,/__[D]ATA__/d' -e '/^# \./!d' -e 's/^# / /' "$0"
)
unset text_only
case "$1" in
-h|--help|-\?)
sed -e 1d -e "s|@@name@@|$(basename $0)|" -e '/^#/!q' -e 's/# *//' $0
printf "Available files:\n%s\n" "$available"
exit
;;
-c)
shift
text_only=1;;
'')
set -- $available
;;
esac
for x; do
name=.${x#.}
sed -n -E "/^# ${name}$/,/^-* EOF -*/p" "$0" \
| if test -n "$text_only"; then
sed -e '1,/^cat/d' -e '$d'
else
cat;
fi \
| if grep .; then
echo "copied $name to clipboard" >&2
else
echo "No text copied to clipboard for $name!" >&2
fi
done \
| expand \
| sed -e "s|@@EMAIL@@|$EMAIL|g" \
| tmux loadb -
exit
# Everything below here is text that gets copied verbatim into the
# tmux buffer, including the commands. The idea is that you can get
# a shell on a new box and setup by pasting this buffer.
## __DATA__
# .gitignore
cat << '-------------- EOF --------------' > $HOME/.gitignore
.kube/http-cache
.kube/cache
.kube/versions.lock
-------------- EOF --------------
# .gitconfig
EMAIL=@@EMAIL@@
cat << EOF > $HOME/.gitconfig &&
[user]
email = ${EMAIL:?}
name = ${USER}
EOF
cat << '-------------- EOF --------------' >> $HOME/.gitconfig
[alias]
ap = add --patch
csa = commit -a -m'Sanity Check'
ciam = commit -a -m
ci = commit
co = checkout
dc = diff --cached
l1 = log --format=format:'%Cgreen%h%Cred %<(10,trunc)%an%Creset %<(60,trunc)%s %Cblue%D%Creset'
l1h = l1 -n 10
s = status -uno
sp = stash pop
ss = stash save
exec = "!exec "
[core]
editor = vim
[color "branch"]
meta = red green bold
[color]
branch = true
-------------- EOF --------------
# .commands
cd "$HOME" &&
ln -s .bash_history $HOME/.bash-history &&
git init &&
if test -f .bashrc ; then git add .bashrc; fi &&
if test -f .gitignore; then git add .gitignore; fi &&
if test -d .kube ; then git add .kube; fi &&
git commit -m 'Save initial config'
: << '-------------- EOF --------------'
-------------- EOF --------------
# .bashrc
grep -q '###$%&^@%$&###' $HOME/.bashrc ||
cat << '-------------- EOF --------------' >> $HOME/.bashrc
#################$%&^@%$&########## content supplied from tmux-setup script#####
read_file() { for f; do test -f "$f" && . "$f"; done; }
unalias -a
shopt -s histappend
trap 'history -a' DEBUG
HISTTIMEFORMAT='%H:%M:%S '
HISTFILESIZE=9999999999
unset PROMPT_COMMAND
export EVENT_NOKQUEUE=1
export LSCOLORS=fxfxcxdxbxegedabagacad
export LESS=FeRXSQM#.95
export SYSTEMD_LESS="${LESS//S/}"
export LC_TIME=C
set -o vi
set -o physical # make pwd do the right thing w.r.t. symbolic links
PS1="\[$(tput rev)"'$( r=$(( $? != 0 )); tput setaf $((2 - r));
tput setab $(( r * 7 ));
)\]\D{%T%z}'"\[$( tput setaf 2)$(tput sgr0)\]"'-$$-\h\$ '
c() { clear; }
g() { git "$@"; }
ta() { tmux attach; }
curl() { command curl -Ss "$@"; }
epoch() { perl -pe 's/([0-9]{9,10})/sprintf "%s (%sUTC)", $1,
scalar gmtime $1/ge' "$@"; }
trim() { perl -nE "chomp; say substr \$_, 0, ${COLUMNS-$(tput cols)} - 1" "$@"; }
vi() { vim "$@"; }
reset_auth_sock() {
local c=$( tmux show-env SSH_AUTH_SOCK 2> /dev/null | cut -d= -f2 )
test -n "$c" && SSH_AUTH_SOCK="$c"
}
trap reset_auth_sock SIGWINCH
complete -r gsutil 2> /dev/null
complete -r gcloud 2> /dev/null
complete -r bq 2> /dev/null
read_file "$HOME"/.bash-local
-------------- EOF --------------
# .bash_profile
cat << '-------------- EOF --------------' > $HOME/.bash_profile
[[ "$-" =~ i ]] && test -n "$BASH" && test -f $HOME/.bashrc && . $HOME/.bashrc
-------------- EOF --------------
# .vimrc
cat << '-------------- EOF --------------' > $HOME/.vimrc
noremap v V
noremap V v
noremap ; :
noremap , ;
syntax on
set nowrapscan
let loaded_matchparen = 1
set path+=~
set includeexpr=substitute(v:fname,'$DAEMON_PATH/','','g')
set t_ti= t_te= " Disable clear screen on exit
set novisualbell
set noerrorbells
set wildmenu
set wildmode=longest,list,full
highlight Comment ctermfg=darkcyan
highlight String ctermfg=darkcyan
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
-------------- EOF --------------
# .inputrc
cat << '-------------- EOF --------------' > $HOME/.inputrc
set editing-mode vi
set keymap vi
-------------- EOF --------------
# .tmux.conf
cat << '-------------- EOF --------------' > $HOME/.tmux.conf
unbind C-b
set -g prefix C-l
bind C-l send-prefix
set -g window-status-current-style fg=yellow,bold,bg=black
set -g window-status-current-format '#{?automatic-rename,#{pane_title},#{window_name}}'
set -g window-status-format '#{?automatic-rename,#{pane_title},#{window_name}}'
set -g status-left-length 25
set -g status-right '%H:%M %e-%b'
set -g status-style bg=red
set-option -g update-environment "SSH_AUTH_SOCK"
set -g history-limit 25000
bind-key -n Left previous-window
bind-key -n Right next-window
bind-key -T root C-b swap-window -t -1
bind-key -T root C-n swap-window -t +1
bind-key C-i rotate-window -D
bind-key ',' command-prompt "rename-window '%%'"
bind-key '$' command-prompt "rename-session '%%'"
# set-hook -g client-attached 'run-shell "kill -s WINCH $(ps -ax | grep [b]ash)"'
-------------- EOF --------------
# .editrc
cat << '-------------- EOF --------------' > $HOME/.editrc
bind -v
-------------- EOF --------------
# .hushlogin
cat << '-------------- EOF --------------' > $HOME/.hushlogin
-------------- EOF --------------