Skip to content

Commit 12e661d

Browse files
authored
Merge pull request #758 from MESAHub/feature/shmesa-version-number
adding capability to print mesa version with shmesa
2 parents 693dd31 + 6fb62a2 commit 12e661d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

scripts/shmesa/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To use, simply call: `shmesa`
1212
\__ \ | | | | | | |___ ___) / ___ \
1313
|___/_| |_|_| |_|_____|____/_/ \_\
1414
15-
Usage: shmesa [work|change|defaults|cp|grep|extras|zip|help] [arguments]
15+
Usage: shmesa [work|change|defaults|cp|grep|extras|zip|version|help] [arguments]
1616
1717
Subcommands:
1818
work copy the work directory to the current location
@@ -22,6 +22,7 @@ Subcommands:
2222
grep search the MESA source code for a given string
2323
extras fill in the full run_star_extras.f90 template
2424
zip prepare a MESA directory for sharing
25+
version print the version of MESA
2526
help display this helpful message
2627
-h get additional details about any of the above
2728
```

scripts/shmesa/shmesa

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ shmesa_help () {
4444
|___/_| |_|_| |_|_____|____/_/ \_\
4545
4646
EOF
47-
echo "Usage: shmesa [work|change|defaults|cp|grep|extras|zip|help] [arguments]"
47+
echo "Usage: shmesa [work|change|defaults|cp|grep|extras|zip|version|help] [arguments]"
4848
echo
4949
echo "Subcommands:"
5050
echo " work copy the work directory to the current location"
@@ -55,6 +55,7 @@ EOF
5555
echo " extras fill in the full run_star_extras.f90 template"
5656
echo " zip prepare a MESA directory for sharing"
5757
echo " help display this helpful message"
58+
echo " version print the version of MESA"
5859
echo " -h flag for getting additional details about any of the above"
5960
echo
6061
}
@@ -252,6 +253,24 @@ shmesa_zip () {
252253
}
253254

254255

256+
shmesa_version() {
257+
if shmesa_check_h_flag "$@"; then
258+
echo "Usage: shmesa version"
259+
echo "prints the version of MESA"
260+
return 0
261+
fi
262+
if [ -f "$MESA_DIR/data/version_number" ]; then
263+
echo "$(cat $MESA_DIR/data/version_number)"
264+
elif [ -d ".git" ] || [ -f ".git" ]; then
265+
# Limits hashes to 7 characters
266+
version=$(git rev-parse HEAD)
267+
echo "%s" "${version:0:7}"
268+
else
269+
echo "Error: Cannot find the version number of MESA."
270+
fi
271+
}
272+
273+
255274
shmesa_extras () {
256275
if shmesa_check_h_flag "$@"; then
257276
echo "Usage: shmesa extras [src/run_star_extras.f90]"
@@ -324,7 +343,7 @@ shmesa_test () {
324343
# since we will be calling shmesa, we need it to be in our path
325344
export PATH=$PATH:$MESA_DIR/scripts/shmesa
326345

327-
# shmesa [work|change|defaults|cp|grep|zip|help]
346+
# shmesa [work|change|defaults|cp|grep|zip|version|help]
328347
rm -rf $MESA_SHMESA_TEST
329348
rm -rf '$MESA_SHMESA_TEST'_cp
330349

@@ -463,6 +482,9 @@ case "$subcommand" in
463482
zip)
464483
shmesa_zip "$@"
465484
;;
485+
version)
486+
shmesa_version "$@"
487+
;;
466488
test)
467489
shmesa_test "$@"
468490
;;

0 commit comments

Comments
 (0)