summaryrefslogtreecommitdiff
path: root/dot/local/bin/tmux-log-everything
diff options
context:
space:
mode:
Diffstat (limited to 'dot/local/bin/tmux-log-everything')
-rwxr-xr-xdot/local/bin/tmux-log-everything40
1 files changed, 40 insertions, 0 deletions
diff --git a/dot/local/bin/tmux-log-everything b/dot/local/bin/tmux-log-everything
new file mode 100755
index 0000000..1e7588b
--- /dev/null
+++ b/dot/local/bin/tmux-log-everything
@@ -0,0 +1,40 @@
1#!/bin/sh
2
3# Inspired by https://github.com/tmux-plugins/tmux-logging via
4# https://unix.stackexchange.com/questions/623054/how-to-automatically-log-all-my-tmux-sessions-to-a-file-in-directory-accordin
5# but massively simplified.
6
7# The tmux-logging plugin usees a different global variable for each pane (named
8# after the pane number) to check whether it is already logging. When the pane
9# is destroyed, the variable stays set. When a new pane is opened, it can
10# recycle the same pane number as before. The plugin will not log to any pane
11# with a recycled pane number!
12#
13# Luckily, tmux supports pane-local variables, which are automatically destroyed
14# when the pane is destroyed! So here we just use one of those.
15
16tmux_log_everything()
17{
18 if ! [ "$TMUX_PANE" ]
19 then
20 return # We are not in tmux
21 fi
22
23 local LOGDIR LOGFILE
24 LOGDIR=$HOME/.tmux-log-everything
25 if ! [ -d "$LOGDIR" ]
26 then
27 return # User has not "requested" logging by creating log dir
28 fi
29
30 if [ "$(tmux show-option -pqv @pane-is-logging)" ]
31 then
32 return
33 fi
34
35 LOGFILE=$LOGDIR/$(date -Is).$$.log.gz
36 tmux set-option -pq @pane-is-logging y
37 tmux pipe-pane "gzip -c > $LOGFILE"
38}
39
40tmux_log_everything