dotfiles/update-motd.d/60-tmux

24 lines
537 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
type tmux >/dev/null 2>&1 || exit 1
set +e; sessions="$(tmux ls 2>&1)"; tmux_exit="$?"; set -e
text=""
if [ $tmux_exit -ne 0 ]; then
text+="no sessions\n"
else
while IFS= read -r line; do
name="$(cut -d ':' -f 1 <<< $line)"
windows="$(cut -d ' ' -f 2,3 <<< $line)"
date="$(cut -d ' ' -f 5,6,7,8 <<< $line)"
text+="$name ($windows) $date\n"
done <<< $sessions
fi
echo "Tmux sessions:"
printf "${text::-2}" | column -ts $',' | sed -e 's/^/ /'
echo ""