2023-03-10 14:11:53 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Best practice options
|
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
|
|
|
|
|
|
|
|
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
|
|
|
|
echo 'Usage:
|
|
|
|
tp new Start a new tmux session (unshared)
|
|
|
|
tp share Share an existing session (read-only)
|
|
|
|
tp sharew Share an existing session (write-access)
|
|
|
|
tp unshare Remove share from existing session
|
|
|
|
'
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-03-12 10:52:54 +00:00
|
|
|
pushd ~
|
2023-03-10 14:11:53 +00:00
|
|
|
|
|
|
|
SOCKET_PATH="/var/tmux_share/shared"
|
|
|
|
SHARED_USER="foxsoft" # Should change this to use getent group tmux
|
|
|
|
|
2023-03-15 09:25:39 +00:00
|
|
|
share_ro_session() {
|
2023-03-10 14:11:53 +00:00
|
|
|
chmod 770 $SOCKET_PATH
|
|
|
|
chgrp tmux $SOCKET_PATH
|
|
|
|
tmux -S $SOCKET_PATH server-access -ar $SHARED_USER
|
|
|
|
}
|
|
|
|
|
|
|
|
share_rw_session() {
|
|
|
|
chmod 770 $SOCKET_PATH
|
|
|
|
chgrp tmux $SOCKET_PATH
|
|
|
|
tmux -S $SOCKET_PATH server-access -aw $SHARED_USER
|
|
|
|
}
|
|
|
|
|
|
|
|
unshare_session() {
|
|
|
|
chmod 700 $SOCKET_PATH
|
|
|
|
tmux -S $SOCKET_PATH server-access -d $SHARED_USER
|
|
|
|
}
|
|
|
|
|
|
|
|
new_session() {
|
|
|
|
tmux -S $SOCKET_PATH new -s shared -d
|
|
|
|
tmux -S $SOCKET_PATH attach
|
|
|
|
}
|
|
|
|
|
2023-03-15 09:25:39 +00:00
|
|
|
attach_to_session() {
|
|
|
|
tmux -S $SOCKET_PATH attach
|
|
|
|
}
|
|
|
|
|
2023-03-10 14:11:53 +00:00
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
|
|
echo "No arguments given. Use -h for help."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-03-15 09:25:39 +00:00
|
|
|
if [[ $1 = "new" || $1 = "n" ]] ; then
|
2023-03-10 14:11:53 +00:00
|
|
|
new_session
|
2023-03-15 09:25:39 +00:00
|
|
|
elif [[ $1 = "sharero" || $1 = "sro" ]] ; then
|
2023-03-10 14:11:53 +00:00
|
|
|
share_session
|
2023-03-15 09:25:39 +00:00
|
|
|
elif [[ $1 = "sharew" || $1 = "srw" ]] ; then
|
2023-03-10 14:11:53 +00:00
|
|
|
share_rw_session
|
|
|
|
elif [[ $1 = "unshare" ]] ; then
|
|
|
|
unshare_session
|
2023-03-15 09:25:39 +00:00
|
|
|
elif [[ $1 = "attach" || $1 = "a" ]] ; then
|
|
|
|
attach_to_session
|
2023-03-10 14:11:53 +00:00
|
|
|
else
|
|
|
|
echo "Unrecognised argument. Use -h for help."
|
|
|
|
fi
|
|
|
|
|
2023-03-12 10:52:54 +00:00
|
|
|
popd
|