Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Based on the answeranswer here is more generic code:

tmuxMany(){
    #http#https://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 panes of equal height.

Based on the answer here is more generic code:

tmuxMany(){
    #http://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 panes of equal height.

Based on the answer here is more generic code:

tmuxMany(){
    #https://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 panes of equal height.

panes of equal height
Source Link

Based on the answer here is more generic code:

tmuxMany(){
    #http://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 tabspanes of equal height.

Based on the answer here is more generic code:

tmuxMany(){
    #http://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 tabs.

Based on the answer here is more generic code:

tmuxMany(){
    #http://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux select-layout even-vertical
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 panes of equal height.

Source Link

Based on the answer here is more generic code:

tmuxMany(){
    #http://unix.stackexchange.com/a/149729/47116
    if [ $# -lt 2 ]; then
        echo usage: sessionName command1 command2 ...
        return 1
    fi
    local sessionName=$1
    local firstCommand=$2
    local secondAndRestCommands=( "${@:3}" )
        
    tmux new-session -s $sessionName -n 'myWindow' -d
    tmux send-keys -t $sessionName:myWindow.0 "$firstCommand" C-j
    local i
    for i in "${!secondAndRestCommands[@]}"
    do
        echo $i
        local command=${secondAndRestCommands[$i]}
        echo $command

        tmux split-window -v
        local tabNumber=$((i+1))
        tmux send-keys -t $tabNumber "$command" C-j
    done
    tmux attach -t $sessionName
}

Usage:

tmuxMany sessionName "tail -f file" "tail -f file2" htop

Will open tmux with 3 tabs.