Skip to content

Instantly share code, notes, and snippets.

@iki
Created June 7, 2010 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iki/428944 to your computer and use it in GitHub Desktop.
Save iki/428944 to your computer and use it in GitHub Desktop.
#!/bin/sh
N="${1:-projectx}"
I="${2:-0}"
echo "=== Opening terminal multiplexer server [$N] session [$I]"
G="tmux-$N" # group name
D="/var/lib/tmux/sockets/$N"
S="$D/.shared"
DP=2770 # set group id = any created file will have the same group as the directory
SP=660
[ -d "$D" ] || { sudo mkdir -p "$D" && sudo chmod "$DP" "$D" && sudo chown "root:$G" "$D" || exit $?; }
if [ ! -e "$S" ] || ! tmux -S "$S" has-session -t "$I"; then
tmux -S "$S" new-session -d -s "$I" && chmod "$SP" "$S" && sudo chown root "$S" || exit $?
# change owner to root, so tmux can't shrink permissions to 600 later
fi
# P=$D/$USER"
# run ln -fT "$S" "$P" # use hardlinked private socket, because tmux will reset its permissions to 600
# (does not help actually, all hardlinks have the same permissions)
# http://comments.gmane.org/gmane.comp.terminal-emulators.tmux.user/557
tmux -S "$S" attach-session -t "$I"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment