open your workspace in multi-screen with only one command

服务端的小伙伴,如果你在使用 vim+screen, 则可以尝试下本文的配置方案,欢迎交流

最终达到的效果:
通过配置 .screenrc 一句命令 自动开启 workspace工作常用的各个目录/服务

  • 自动登陆mongo cli (我这里是 localhost:27117转发的remote的27017)
  • 自动登陆到测试服务器 remote
  • 自动进入 /home/ganiks/workspace/one-command-open-workspace/dir1 并启动god服务到8888端口
  • 自动进入/home/ganiks/workspace/one-command-open-workspace/dir2 并启动rest服务到9999端口
  • 自动进入常用目录 /home/ganiks/workspace/one-command-open-workspace/dir1/apps
  • 自动进入常用目录 /home/ganiks/workspace/one-command-open-workspace/dir1/template
  • 自动进入常用目录 /home/ganiks/workspace/one-command-open-workspace/dir2/apps

而这些 window的切换仅仅需要 ctrl+Z+[0~9] 就可以快速切换

.screenrc 配置分为两部分

screen 全局样式和自定义部分

# GNU Screen - main configuration file 
# All other .screenrc files will source this file to inherit settings.
# Author: Christian Wills - [email protected]

# Allow bold colors - necessary for some reason
attrcolor b ".I"

# Tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'

# Enables use of shift-PgUp and shift-PgDn
termcapinfo xterm|xterms|xs|rxvt ti@:te@

# Erase background with current bg color
defbce "on"

# Enable 256 color term
term xterm-256color

# Cache 30000 lines for scroll back
defscrollback 30000

# New mail notification
backtick 101 30 15 $HOME/bin/mailstatus.sh

hardstatus alwayslastline 
# Very nice tabbed colored hardstatus line
hardstatus string '%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %C%A%{-}'

# change command character from ctrl-a to ctrl-b (emacs users may want this)
escape ^Zz #我习惯用 ctrl+z 作为screen 热键(默认是 a)

# Hide hardstatus: ctrl-a f 
bind f eval "hardstatus ignore"
# Show hardstatus: ctrl-a F
bind F eval "hardstatus alwayslastline"

screen会话自定义服务和目录部分

################
# one-command-open-workspace   #
################
#
# s27117remote # sudo kill -9 $(sudo lsof -t -i:27117) && ssh -fNL 27117:localhost:27017 -p 8888 ganiks@remote > /dev/null
#
chdir /home/ganiks
################
# sudo lsof -i:27117
# mongo localhost:27117
################
#screen -t mongo ./screen-mongo.sh 
screen -t mongo mongo localhost:27117 

################
# ssh -p 8888 ganiks@$1
################
#screen -t remote s remote 
screen -t remote ssh -p 8888 ganiks@remote

chdir /home/ganiks/workspace/one-command-open-workspace
chdir dir1 
screen -t god8888 python main.py
chdir ../dir2 
screen -t rest9999 python main.py --port=9999 
chdir ../dir1/apps 
screen -t god/apps 
chdir ../template 
screen -t god/template 
chdir ../../dir2/apps 
screen -t rest/apps 

附一个连接 remote:27117脚本

sudo kill -9 $(sudo lsof -t -i:27117) && ssh -fNL 27117:localhost:27017 -p 8888 ganiks@remote > /dev/null 2>&1

使用方法:

s27117remote && screen -S one-command-open-workspace

就可以进入到如图的工作空间啦~

你可能感兴趣的:(open your workspace in multi-screen with only one command)