Skip to content

Instantly share code, notes, and snippets.

@atucom
Last active October 29, 2018 23:22
Show Gist options
  • Save atucom/5140645 to your computer and use it in GitHub Desktop.
Save atucom/5140645 to your computer and use it in GitHub Desktop.
tmux logging hack. Works just like GNU screen "logfile"
#!/bin/bash
#place this code in your .bashrc or .profile and have fun :D
if [[ $(uname) = "Darwin" ]]; then #this is for OSX Machines
#This sets up auto logging to $HOME/logs if its a tmux window
if [[ $TERM = "screen" ]] && [[ $(ps $PPID -o comm=) = "tmux" ]] ; then
read -p "Enter Log Prefix: " log_prefix
logname="${log_prefix}_$(date '+%d.%m.%Y-%H:%M:%S').tmux.log"
mkdir $HOME/logs 2> /dev/null
script -t 1 $HOME/logs/${logname} bash -login
exit
fi
fi
#LINUX SPECIFIC CODE
if [[ $(uname) = "Linux" ]]; then #this is for Linux
if [[ $TERM = "screen" ]] && [[ $(ps -p $PPID -o comm=) = "tmux" ]]; then
read -p "Enter Log Prefix: " log_prefix
logname="${log_prefix}_$(date '+%d.%m.%Y-%H:%M:%S').tmux.log"
mkdir $HOME/logs 2> /dev/null
script -f $HOME/logs/${logname}
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment