tmux pairing script
This commit is contained in:
commit
72408929fc
|
@ -0,0 +1,62 @@
|
|||
#!/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
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
SOCKET_PATH="/var/tmux_share/shared"
|
||||
SHARED_USER="foxsoft" # Should change this to use getent group tmux
|
||||
|
||||
share_session() {
|
||||
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
|
||||
}
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo "No arguments given. Use -h for help."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ $1 = "new" ]] ; then
|
||||
new_session
|
||||
elif [[ $1 = "share" ]] ; then
|
||||
share_session
|
||||
elif [[ $1 = "sharew" ]] ; then
|
||||
share_rw_session
|
||||
elif [[ $1 = "unshare" ]] ; then
|
||||
unshare_session
|
||||
else
|
||||
echo "Unrecognised argument. Use -h for help."
|
||||
fi
|
||||
|
Loading…
Reference in New Issue