Split tmux panes like bspwm

Description

bspwm is my favourite tiling window manager.

By default, it opens new windows along the “widest” direction. This behavior is very natural for me, so I decided to replicate this inside tmux. As a result, I need only a single keybinding to split my tmux panes without needing to think about and specify in which direction I want the pane to split.

Script

Here’s the simple script that allows splitting tmux panes the same way as default bspwm behavior:

#!/bin/sh
pane_height=$( expr $(tmux display-message -p '#{pane_height}') \* 3)
pane_width=$(tmux display-message -p '#{pane_width}')

if [  "$pane_width" -gt "$pane_height" ]; then
    tmux split-window -h -c'#{pane_current_path}'
else
    tmux split-window -v -c'#{pane_current_path}'
fi

Usage

Save the above snippet as ~/.config/tmux/split Then invoke it with your preferred keybinding from tmux.conf, like so:

bind Enter run-shell ~/.config/tmux/split

Demonstration

tmux-split.gif