9
9
# #
10
10
# # * `--pid`: get the process id for the notebook (if any)
11
11
# #
12
+ # # * `-R|--repo`: change marimo repository (default `arras-energy/marimo`)
13
+ # #
12
14
# # * `--upgrade`: upgrade marimo to latest version
13
15
# #
14
16
# # * `--url`: get the URL for the notebook (if any)
17
19
# #
18
20
# # * `--wait`: wait for marimo server to exit
19
21
# #
22
+ # # * `-W|--workdir`: change work directory (default `gridlabd-marimo`)
23
+ # #
20
24
# # Commands:
21
25
# #
22
26
# # * `edit NOTEBOOK`: open the notebook in the marimo editor
53
57
54
58
LIB=$GLD_ETC /marimo
55
59
LOG=$LIB /marimo.log
56
- URL=https://raw.githubusercontent.com/arras-energy/marimo/refs/heads/main/source
57
60
WAIT=no
61
+ WORKDIR=gridlabd-marimo
58
62
59
63
E_OK=0
60
64
E_SYNTAX=1
61
65
E_FAIL=2
62
66
E_NOTFOUND=3
63
67
E_MISSING=4
64
68
69
+ function repo()
70
+ {
71
+ if [ $# -eq 0 ]; then
72
+ error " missing repo name" E_MISSING
73
+ fi
74
+ URL=https://raw.githubusercontent.com/$1 /refs/heads/main/source
75
+ API=https://api.github.com/repos/$1 /contents/source
76
+ GIT=https://github.com/$1
77
+ }
78
+ repo arras-energy/marimo
79
+
65
80
function error()
66
81
{
67
82
# error MESSAGE [EXITCODE]
@@ -90,7 +105,7 @@ function index()
90
105
if [ " $( gridlabd.bin --version=branch) " == " master" ]; then
91
106
curl -sL -H ' Cache-Control: no-cache' $URL /.index 2>> $LOG
92
107
else
93
- curl -sL -H ' Cache-Control: no-cache' https://api.github.com/repos/arras-energy/marimo/contents/source 2>> $LOG | grep ' "name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd " A-Za-z0-9_\\ n"
108
+ curl -sL -H ' Cache-Control: no-cache' $API 2>> $LOG | grep ' "name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd " A-Za-z0-9_\\ n"
94
109
fi
95
110
}
96
111
@@ -175,20 +190,30 @@ function edit()
175
190
elif [ " $( gridlabd.bin --version=branch) " == " master" ]; then
176
191
error " you must use a development version of gridlabd" E_FAIL
177
192
fi
178
- if [ -d gridlabd-marimo ]; then
179
- ( cd gridlabd-marimo ; git pull )
193
+ if [ -d " $WORKDIR " ]; then
194
+ ORIGIN=$( cd " $WORKDIR " ; git remote get-url origin)
195
+ if [ " $URL " != " $ORIGIN " ]; then
196
+ warning " repository '$GIT ' does not match '$WORKDIR ' origin '$ORIGIN ', unable to pull"
197
+ elif [ ! -d " $WORKDIR /.git" ]; then
198
+ warning " '$WORKDIR ' is not a git repository (you cannot commit changes), unable to pull"
199
+ else
200
+ ( cd " $WORKDIR " ; git pull )
201
+ fi
180
202
else
181
- git clone https://github.com/arras-energy/marimo gridlabd-marimo
203
+ git clone $GIT " $WORKDIR " || error " clone failed " E_FAIL
182
204
fi
183
- if [ ! -d gridlabd-marimo /source ]; then
205
+ if [ ! -d " $WORKDIR /source" ]; then
184
206
error " clone failed" E_FAIL
185
207
else
186
- if [ ! -f gridlabd-marimo /source/$1 .py ]; then
187
- echo " Creating gridlabd-marimo /source/$1 .py"
208
+ if [ ! -f " $WORKDIR /source/$1 .py" ]; then
209
+ echo " Creating ' $WORKDIR /source/$1 .py' "
188
210
fi
189
- ( cd gridlabd-marimo/source ; marimo edit $1 .py )
211
+ echo " Opening marimo notebook..." > /dev/stderr
212
+ ( cd " $WORKDIR /source" ; marimo edit " $1 .py" )
213
+ fi
214
+ if [ -d " $WORKDIR /.git" ]; then
215
+ warning " don't forget to add/commit/push changes to '$WORKDIR ' when done editing"
190
216
fi
191
- warning " don't forget to add/commit/push when done editing"
192
217
}
193
218
194
219
function open()
@@ -228,6 +253,10 @@ while [ $# -gt 0 ]; do
228
253
getpid $2
229
254
shift 1
230
255
;;
256
+ -R|--repo)
257
+ repo $2
258
+ shift 1
259
+ ;;
231
260
--upgrade)
232
261
python3 -m pip install --upgrade marimo
233
262
shift 1
@@ -242,6 +271,13 @@ while [ $# -gt 0 ]; do
242
271
--wait)
243
272
WAIT=yes
244
273
;;
274
+ -W|--workdir)
275
+ if [ $# -eq 1 ]; then
276
+ error " missing folder name" E_MISSING
277
+ fi
278
+ WORKDIR=$2
279
+ shift
280
+ ;;
245
281
index) # list of available apps
246
282
index
247
283
exit $E_OK
0 commit comments