Skip to content

Instantly share code, notes, and snippets.

@iki

iki/tmux4group.sh

Created Jun 7, 2010
Embed
What would you like to do?
#!/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