Set tmux as the default shell in WSL
To set tmux as your default shell on WSL Linux, you can modify your shell’s configuration file. Here’s a step-by-step guide:
-
Locate Your Shell Configuration File:
bash nano ~/.bashrc
-
Add Conditional Statements: At the end of the file, add the following code:
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then tmux attach-session -t default || tmux new-session -s default fi
This ensures that:
Tmux is installed (
command -v tmux
). You’re not already in a tmux session ([ -z "$TMUX" ]
). It tries to attach to an existing session nameddefault
or creates a new one. - Save and Exit: Press
Ctrl+O
to save andCtrl+X
to exit the editor. -
Apply Changes: Run the following command to apply the changes:
source ~/.bashrc
Or restart your terminal.