Duplicate Pane: Show History in tmux
tmux is a popular terminal multiplexer that allows users to run multiple terminal sessions within a single window. It enables you to split the terminal window into several panes, switch between sessions, and detach sessions from the terminal, among other features. In this article, we will focus on how to duplicate a pane and show its history in tmux.
Duplicating a Pane in tmux
To duplicate a pane in tmux, follow these steps:
- Launch tmux and create a new session.
- Split the current window into two panes using the
split-windowcommand. - In the pane you want to duplicate, run the command
command-prompt -I "#{pane_title}" "detach-client -s #{session_name} -t #{pane_tty} && rename-window -t #{session_name} #{pane_title} && attach-session -t #{session_name}".
The above command does the following:
- It detaches the current client from the pane.
- It renames the current window to the title of the pane being duplicated.
- It attaches the client to the new session.
# Duplicate pane and show its history
bind-key D command-prompt -I "#{pane_title}" "detach-client -s #{session_name} -t #{pane_tty} && rename-window -t #{session_name} #{pane_title} && attach-session -t #{session_name}"
You can add the above code to your .tmux.conf file to bind the key D to the command, which duplicates the current pane and shows its history.
Showing History in tmux
To show the history of a pane or a window, you can use the capture-pane and list-windows commands, respectively. Here's how:
- To show the history of the current pane, run the command
capture-pane -p -S -e -J -t #{pane_tty}. - To show the history of the current window, run the command
list-windows -a -F '#{window_index} #{window_active} #{window_flags} #{window_pid} #{window_creator} #{window_layout} #{window_activity} #{window_session_name}'.
Duplicating a pane and showing its history can be handy in many situations, such as when you want to compare the output of two commands or when you want to keep a record of a command's output for future reference. With tmux, you can easily achieve this using the commands we have covered in this article.