Created
December 26, 2019 05:09
-
-
Save krast/8b3a9edd00b34514fb3cddf77ff9f250 to your computer and use it in GitHub Desktop.
tmux-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TCPKeepAlive yes | |
ServerAliveInterval 60 | |
ServerAliveCountMax 10 | |
StrictHostKeyChecking no | |
UserKnownHostsFile /dev/null | |
Host jumpserver | |
User krast | |
Hostname jumpserver.krast.net | |
Port 6666 | |
BatchMode yes | |
ProxyCommand none | |
identityfile ~/.ssh/private_key | |
TCPKeepAlive yes | |
ServerAliveInterval 60 | |
ForwardAgent yes | |
StrictHostKeyChecking no | |
UserKnownHostsFile /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------- | |
# tmuxrc settings | |
#--------------------------------------- | |
SESSION_NAME={{ session-name }} | |
DEFAULT_PATH=~/workspace | |
PRIVATE_KEY="" | |
SSH_CONFIG=“/Users/krast/.ssh/config” | |
# following commands will be executed first, in each window | |
pre_input="echo '#######################' && echo '## $SESSION_NAME workstation' && echo '#######################'" | |
# define commands | |
# 'name' 'command' | |
declare -a input | |
for i in `seq 50 60`; | |
do | |
input+=($i) | |
input+=("ssh -t -o ProxyCommand='ssh -F $SSH_CONFIG -A -q -W 10.10.10.$i:22 jumpserver' [email protected].$i") | |
done | |
for i in `seq 100 200`; | |
do | |
input+=($i) | |
input+=("ssh -t -o ProxyCommand='ssh -F $SSH_CONFIG -A -q -W 10.20.20.$i:22 jumpserver' [email protected].$i") | |
done | |
if [ -z ${TMUX} ]; | |
then | |
TMUX= tmux new-session -s $SESSION_NAME -d -c $DEFAULT_PATH | |
echo "Starting new session." | |
else | |
SESSION_NAME="$(tmux display-message -p '#S')" | |
fi | |
# create arrays of names and commands | |
for ((i=0; i < ${#input[*]}; i++)); | |
do | |
((i%2==0)) && names[$i/2]="${input[$i]}" | |
((i%2==1)) && cmds[$i/2]="${input[$i]}" | |
done | |
# run tmux windows | |
for ((i=0; i < ${#names[*]}; i++)); | |
do | |
tmux new-window -t $SESSION_NAME:$(($i+10)) -n "${names[$i]}" -c $DEFAULT_PATH | |
done | |
# send commands | |
for ((i=0; i < ${#cmds[*]}; i++)); | |
do | |
tmux send-keys -t $SESSION_NAME:$(($i+10)) "${pre_input}" Enter; | |
tmux send-keys -t $SESSION_NAME:$(($i+10)) "${cmds[$i]}" Enter; | |
done | |
sleep 4 | |
tmux select-window -t $SESSION_NAME:0 | |
tmux -2 attach-session -t $SESSION_NAME | |
clear | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------- | |
# tmuxrc settings | |
#--------------------------------------- | |
#color config | |
set -g default-terminal "screen-256color" | |
#up | |
bind-key k select-pane -U | |
#down | |
bind-key j select-pane -D | |
#left | |
bind-key h select-pane -L | |
#right | |
bind-key l select-pane -R | |
setw -g mode-keys vi # vi key | |
set-option -g allow-rename off | |
set-option -g history-limit 50000 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir ~/.tmux | |
mv tmux.conf ~/.tmux.conf | |
mv tmux-template.conf ~/.tmux-template.conf | |
# 参数解释 | |
# ---------- | |
SESSION_NAME tmux的session名 | |
DEFAULT_PATH 本地工作目录 | |
PRIVATE_KEY ssh私钥 | |
SSH_CONFIG ssh配置 | |
tmux -c ~/.tmux/.tmux-template.conf |
Good~~!
Wonderful~~~!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool~~~!