All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 LASTSESSIONIDFILE="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/tmux-last-session-id"
8 if [ -n "${_tmux_eval_only:-}" ]; then
11 $exec $(which -a tmux | grep -v $HOME | head -1) "$@"
14 single_tmux_session() {
15 local id; id="$1"; shift
17 real_tmux list-sessions | grep -q "^${id}:" || flag=s
18 real_tmux new -$flag "$id" "$@"
21 tmux_session_exists() {
22 _tmux_eval_only=1 real_tmux has-session -t "$1"
25 if [ "${1:-}" = last ]; then
27 if [ -f "$LASTSESSIONIDFILE" ]; then
28 UUID="$(cat $LASTSESSIONIDFILE)"
29 if tmux_session_exists $UUID; then
30 echo >&2 Attaching to existing session with ID $UUID…
31 single_tmux_session "$(cat $LASTSESSIONIDFILE)" "$@"
33 echo >&2 W: No tmux session with ID $UUID found, generating a new one…
36 echo >&2 W: No tmux session ID stored, generating a new one…
46 # only without argument create a new session with a random name/id to which we
49 hascmd() { command -v "$@" >/dev/null;}
51 if hascmd uuid; then alias uuidgen=uuid
52 elif hascmd uuidgen; then :
53 elif hascmd python3; then
54 uuidgen() { python3 -c 'import uuid; print(uuid.uuid1())'; }
55 elif hascmd python; then
56 uuidgen() { python -c 'import uuid; print(uuid.uuid1())'; }
58 uuidgen() { dd if=/dev/urandom bs=16 count=1 status=none | base64; }
61 echo "$UUID" > $LASTSESSIONIDFILE
63 echo >&2 Starting a new session with ID $UUID…
65 single_tmux_session $UUID "$@"