-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmws
executable file
·118 lines (97 loc) · 3.14 KB
/
tmws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#
# Start or attach to a tmux session in a workspace
#
# Standard functions
GTWS_LOC=$(readlink -f $(dirname "$0"))
source ${GTWS_LOC}/gtws.sh
if [ -f "${PWD}/.gtwsrc" ]; then
load_rc "${PWD}"
else
source "${HOME}/.gtwsrc"
fi
if [ -n "${GTWS_PROJECT_VERSION}" ]; then
VERSION="${GTWS_PROJECT_VERSION}"
elif [ -n "${GTWS_DEFAULT_PROJECT_VERSION}" ]; then
VERSION="${GTWS_DEFAULT_PROJECT_VERSION}"
else
VERSION=$(basename "$PWD");
fi
if [ -n "${GTWS_PROJECT}" ]; then
PROJECT="${GTWS_PROJECT}"
elif [ -n "${GTWS_DEFAULT_PROJECT}" ]; then
PROJECT="${GTWS_DEFAULT_PROJECT}"
else
PROJECT=$(basename $(dirname "$PWD"));
fi
# Set usage output
DESCRIPTION="Start or attache to a tmux session in a workspace"
USAGE="[-h |--help] [-p <project> | --project=<project>] [-v <version> | --version=<version>] [-V | --verbose] <name>"
LONGUSAGE="\t-h, --help\n\t\tPrint this help message
\t-p <project>, --project=<project>\n\t\tProject (default: ${PROJECT:-none})
\t-v <version>, --version=<version>\n\t\tProject version (default: ${VERSION})
\t-V, --verbose\n\t\tBe verbose
\t<name>\n\t\tWorkspace name"
# Script name
ME=$(basename $0)
# Parse arguments
ARGS=`getopt -o hVp:v: --long help,verbose,project:,version: -n "${ME}" -- "$@"`
if [ $? != 0 ] ; then
usage
fi
eval set -- "$ARGS"
while true ; do
case "$1" in
-h|--help) usage; shift ;;
-p|--project) PROJECT=$2 ; shift 2 ;;
-v|--version) VERSION=$2 ; shift 2 ;;
-V|--verbose) export GTWS_VERBOSE=yes; shift ;;
--) shift ; break ;;
* ) usage "Invalid argument $1";;
esac
done
# Remaining arguments are in $1, $2, etc. as normal
if [ -n "${1}" ]; then
GTWS_WSNAME="${1%/}"
fi
if [ -z "${GTWS_WSNAME}" ]; then
usage "Must give a workspace name"
fi
# We're going to clear the environment before starting tmux, so use a non-GTWS prefix
WSNAME="${GTWS_WSNAME}"
if [ -z "${PROJECT}" ]; then
usage "Must give a project"
fi
BASE=${GTWS_BASE_SRCDIR:-${HOME}/src}
if [ ! -f "${BASE}/${PROJECT}/${VERSION}/${WSNAME}/.gtwsrc" ]; then
usage "No .gtwsrc for ${PROJECT}/${VERSION}/${WSNAME}"
fi
if [ -n "$TMUX" ]; then
usage "Do not run from within tmux"
fi
gtws_tmux_session_name ${PROJECT} ${VERSION} ${WSNAME} SESNAME
cd "${BASE}/${PROJECT}/${VERSION}/${WSNAME}"
# Clear the env, or it may end up in the tmux server, corrupting non-ws sessions
GTWS_SAVEVARS="XXNOPEXX"
clear_env
gtws_tmux_session_info "${SESNAME}" RUNNING ATTACHED
echo "RUNNING=$RUNNING ATTACHED=$ATTACHED"
if ! ${RUNNING} ; then
echo "Launching tmux base session ${SESNAME} ..."
tmux new-session -s ${SESNAME} -n "Edit" "startws -p ${PROJECT} -v ${VERSION} -t Edit ${WSNAME}" \; \
new-window -n "Build" "startws -p ${PROJECT} -v ${VERSION} -t Test ${WSNAME}" \; \
split-window -v "startws -p ${PROJECT} -v ${VERSION} -t Util ${WSNAME}" \; \
split-window -v "startws -p ${PROJECT} -v ${VERSION} -t Build ${WSNAME}" \; \
select-layout even-horizontal \; \
select-window -t :0 \; \
set-option -g status-left "${HOSTNAME}:#S"
else
gtws_tmux_cleanup
if ${ATTACHED} ; then
echo "Slaving to workspace ${SESNAME} ..."
gtws_tmux_slave "${SESNAME}"
else
echo "Attaching to workspace ${SESNAME} ..."
gtws_tmux_attach "${SESNAME}"
fi
fi