Skip to content

Instantly share code, notes, and snippets.

@ljjjustin
Last active December 18, 2019 03:25
Show Gist options
  • Save ljjjustin/e395c518ab71ec659f05d781661e8705 to your computer and use it in GitHub Desktop.
Save ljjjustin/e395c518ab71ec659f05d781661e8705 to your computer and use it in GitHub Desktop.
create a shared tmux session
#!/bin/bash
mksock() {
local SOCK=$1
if [ ! -e ${SOCK} ]; then
SF="$1" python -c "import os, socket as s; s.socket(s.AF_UNIX).bind(os.environ['SF'])"
fi
}
enter_tmux_session() {
local session=$1
local sockfile="/tmp/${session}"
local tmux=$(/usr/bin/which tmux)
mksock $sockfile && chmod 777 $sockfile
${tmux} -S $sockfile attach -t ${session} || ${tmux} -S $sockfile new -s ${session}
}
session="ops$(date '+%m%d')"
enter_tmux_session ${session}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment