-
Notifications
You must be signed in to change notification settings - Fork 1
/
workspaces.sh
executable file
·54 lines (43 loc) · 1006 Bytes
/
workspaces.sh
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
# this is not a standalone shell script.
: ${workspaces[@]:?This script is not intended to be executed}
: ${PREFIX:?}
set -e
open_workspace ()
{
local wname="$1" pkg p
p=$PREFIX/$wname
pkg=${workspaces[$wname]:?Workspace $wname not found.}
if ! [[ -d "$p" ]]; then
mkdir -p "$p" # side effect
# First time opening this workspace, call 'workspace-init'
cd "$p"
"$pkg"/bin/workspace-init
fi
cd "$p"
"$pkg"/bin/workspace-activate
}
USAGE_OPEN="open <workspace name>"
USAGE_LIST="list"
cmd=$1
shift
case "$cmd" in
"open")
wname=${1:?Usage: workspaces $USAGE_OPEN}
open_workspace "$wname"
;;
"list")
for wname in "${!workspaces[@]}"; do
echo "$wname"
done
;;
*)
cat <<EOF >&2
Usage: workspaces { open | list }
$USAGE_OPEN
Open the specified workspace. A directory in $PREFIX is created if it
doesn't exist, the activation script is run and finally the shell is opened.
$USAGE_LIST
List workspaces.
EOF
;;
esac