Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

full manuals

Ref Ref2

auto completion in bash

Ref1 Ref2

cd /usr/share/bash-completion/completions/
wget https://raw.githubusercontent.com/imomaliev/tmux-bash-completion/master/completions/tmux

auto completion in tmux terminal

install basic config

configure history limit

Create the ~/.tmux.conf file and put the following line there:

set-option -g history-limit 10000

dump history of a session

# before dump, you should have the identifier of session, window and pane using the following commands
tmux list-sessions
tmux list-windows -t <session-name>
tmux list-panes -t <session-name>:<window-number>

# capture pane history
tmux capture-pane -t <session-name>:<window-number>.<pane-number> -S -10000 -p > ~/tmux-pane-history.txt

dump all windows and their panes

If your session contains multiple windows and panes, and you want to capture the history from all of them, you can use a shell script to automate the process:

#!/bin/bash

SESSION_NAME="your-session-name"
OUTPUT_DIR="$HOME/tmux-session-history"

mkdir -p "$OUTPUT_DIR"

# Iterate through each window
tmux list-windows -t "$SESSION_NAME" -F "#{window_index}" | while read -r WINDOW_INDEX; do
  # Iterate through each pane in the window
  tmux list-panes -t "$SESSION_NAME:$WINDOW_INDEX" -F "#{pane_index}" | while read -r PANE_INDEX; do
    FILE_NAME="session-${SESSION_NAME}_window-${WINDOW_INDEX}_pane-${PANE_INDEX}.txt"
    tmux capture-pane -t "${SESSION_NAME}:${WINDOW_INDEX}.${PANE_INDEX}" -S -10000 -p > "${OUTPUT_DIR}/${FILE_NAME}"
    echo "Captured ${FILE_NAME}"
  done
done

kill session

tmux kill-session -t <session-name>