tmux懒人启动和关闭脚本
tmux启动,选择启动几个window,每个window平均分4个panel
如:
1. 将启动脚本保存到 tmuxs.sh文件中,将关闭脚本保存到tmuxk.sh文件中。
2. 启动终端,执行tmuxs.sh,输入3,将创建3个window,每个window分4个panel
3. 执行tmuxk.sh,将关闭所有的windows
启动:
#!/usr/bin/env bash
echo "create windows count:"
read winCnt
cmd=$(which tmux) # tmux path
session=work # session name
if [ -z $cmd ]; then
echo "You need to install tmux."
exit 1
fi
$cmd has -t $session
if [ $? != 0 ]; then
#new session, window name is "env"
$cmd new -s $session -d -n window0
for ((i=0; i < winCnt; i++))
do
winName=window$i
echo $winName
if [ $winName != window0 ]; then
#new window "i"
$cmd neww -n $winName -t $session -d
$cmd selectw -t $session:$winName
fi
#split window ""
$cmd splitw -v -p 50 -t $winName
$cmd splitw -h -p 50 -t $winName
$cmd selectp -t 0
$cmd splitw -h -p 50 -t $winName
$cmd selectp -t 0
done
#select first window
$cmd selectw -t $session:window0
fi
$cmd att -t $session
exit 0
关闭:
#!/usr/bin/env bash
tmux kill-session -t work