brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: open new tmux panes in the folder you are already in

Tmux
~/tips/tip-tmux-split-current-path

bind | split-window -h -c "#{pane_current_path}"

Makes tmux splits and new windows start in the current pane's directory instead of your home folder.

By default a new pane starts in the directory where the session began, which is rarely where you are working.

bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"

Now Ctrl-b | and Ctrl-b - split left-right and top-bottom, and the new pane opens in the same folder. The c line does the same for new windows.

This is one of the first things I would put in a config. You open a pane to run a command next to the one you are in, and almost always you want to be in the same folder. Without the option you land in your home folder or the folder where the session was created, and have to type cd again.

The -c flag of split-window and new-window takes a start directory, and #{pane_current_path} is the format variable that holds the current pane’s folder. The quotes around it matter, because paths can contain spaces. The two bind lines also give you split keys you can remember, with | for left-right and - for top-bottom.

pane_current_path comes from the shell, so it is only right when the program in the pane reports its directory, which a normal shell does.

Try it without risk: start a throwaway session with tmux new -s scratch, use the shortcut or command above there, look at what changes, and close the session again with tmux kill-session -t scratch.

Further reading: tmux manual page (OpenBSD, official), tmux wiki: Getting Started (official), On this site: tmux select-layout tidies a mess of panes in one command, On this site: Ctrl-b Alt-arrow resizes a tmux pane five cells at a time

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link