summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-09 16:15:02 -0400
committerAndrew Cady <d@jerkface.net>2022-10-09 16:27:00 -0400
commit6cf2a9da6789cfd9cb204371062e6c325efa38e6 (patch)
treec511b24164614cfe101da5bbd47408a2684ea7b1
parent3e888e59b3add9a9a5e7418c647654b559751bdb (diff)
automatically log all tmux sessions if $HOME/.tmux-log-everything/ exists
-rw-r--r--dot/bashrc2
-rwxr-xr-xdot/local/bin/tmux-log-everything40
2 files changed, 42 insertions, 0 deletions
diff --git a/dot/bashrc b/dot/bashrc
index 36d6b6b..121ad51 100644
--- a/dot/bashrc
+++ b/dot/bashrc
@@ -60,6 +60,8 @@ memoize_retval()
60 add_path -a /usr/games 60 add_path -a /usr/games
61 add_path "$HOME/.cabal/bin" "$HOME/.local/bin" "$HOME/bin" 61 add_path "$HOME/.cabal/bin" "$HOME/.local/bin" "$HOME/bin"
62 62
63 tmux-log-everything
64
63# if have stack; then 65# if have stack; then
64# add_stack_binpath 66# add_stack_binpath
65# fi 67# fi
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