Skip to content

Instantly share code, notes, and snippets.

@TheTechromancer
Created February 4, 2021 20:18
Show Gist options
  • Save TheTechromancer/65b7571fda899b3a73bfb04c9fb75447 to your computer and use it in GitHub Desktop.
Save TheTechromancer/65b7571fda899b3a73bfb04c9fb75447 to your computer and use it in GitHub Desktop.
Enable complete session logging (input and output) for both normal shells and individual tmux panes
# default tmux config
cat <<EOF > "$HOME/.tmux.conf"
set -g mouse on
set -g history-limit 50000
# List of plugins
set -g @plugin 'tmux-plugins/tmux-logging'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
EOF
# enable command aliasing
shopt -s expand_aliases
# skip prompts in apt-upgrade, etc.
export DEBIAN_FRONTEND=noninteractive
alias apt-get='yes "" | apt-get -o Dpkg::Options::="--force-confdef" -y'
apt-get install tmux-plugin-manager
mkdir -p "$HOME/.tmux/plugins" 2>/dev/null
export XDG_CONFIG_HOME="$HOME"
export TMUX_PLUGIN_MANAGER_PATH="$HOME/.tmux/plugins"
/usr/share/tmux-plugin-manager/scripts/install_plugins.sh
mkdir -p "$HOME/Logs" 2>/dev/null
# tmux logging needs to go in /etc/profile
grep -q 'TMUX_LOGGING' "/etc/profile" || echo '
logdir="$HOME/Logs"
if [ ! -d $logdir ]; then
mkdir $logdir
fi
#gzip -q $logdir/*.log &>/dev/null
export XDG_CONFIG_HOME="$HOME"
export TMUX_PLUGIN_MANAGER_PATH="$HOME/.tmux/plugins"
if [[ ! -z "$TMUX" && -z "$TMUX_LOGGING" ]]; then
logfile="$logdir/tmux_$(date -u +%F_%H_%M_%S)_UTC.$$.log"
"$TMUX_PLUGIN_MANAGER_PATH/tmux-logging/scripts/start_logging.sh" "$logfile"
export TMUX_LOGGING="$logfile"
fi' >> "/etc/profile"
# normal logging goes in .bashrc and .zshrc
normal_log_script='
logdir="$HOME/Logs"
if [ ! -d $logdir ]; then
mkdir $logdir
fi
if [[ -z "$NORMAL_LOGGING" && ! -z "$PS1" && -z "$TMUX" ]]; then
logfile="$logdir/$(date -u +%F_%H_%M_%S)_UTC.$$.log"
export NORMAL_LOGGING="$logfile"
script -f -q "$logfile"
exit
fi'
grep -q 'NORMAL_LOGGING' "$HOME/.bashrc" || echo "$normal_log_script" >> "$HOME/.bashrc"
grep -q 'NORMAL_LOGGING' "$HOME/.zshrc" || echo "$normal_log_script" >> "$HOME/.zshrc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment