tmux懶人啓動和關閉腳本

tmux啓動1個窗口,選擇啓動幾個session,每一個session平均分4個panelwindows

啓動:bash

#!/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
        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 0session

 

關閉:cmd

#!/usr/bin/env bash

tmux kill-session -t work it

相關文章
相關標籤/搜索