Granular.jl

Julia package for granular dynamics simulation
git clone git://src.adamsgaard.dk/Granular.jl
Log | Files | Refs | README | LICENSE

commit 91f51bd10b33949493671db8ac2b333eb0aca594
parent 5d42f7db81bf61b204edebb53e9d07b164463f33
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 10 Apr 2019 14:36:17 +0200

Improve functionality of shell status script

Diffstat:
Mgranular-status.sh | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 73 insertions(+), 20 deletions(-)

diff --git a/granular-status.sh b/granular-status.sh @@ -1,23 +1,76 @@ -#!/bin/bash +#!/usr/bin/env bash -# Status script which traverses the subdirectories of the current folder for -# simulations. You may want to add this to your shell's PATH variable. +version=1.0 +loopinterval=10 -set -e -cmd_single='julia --color=yes -e "import Granular; Granular.status()"' -cmd_loop='julia --color=yes -e "import Granular; Granular.status(loop=true, t_int=10)"' -cmd_render='julia --color=yes -e "import Granular; Granular.status(visualize=true)"' +function show_help { + echo "usage: ${0##*/} [OPTIONS] [COMMAND]" + echo "Status script which traverses the subdirectories of the current " + echo "directory for simulations." + echo + echo "The following COMMANDS are supported:" + echo " loop continuously show status of simulations" + echo " render continuously show status of simulations" + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -n, --interval SECONDS sleep duration between status loops" + echo " -- do not consider any following args as options" +} -if [[ "$1" == "loop" ]]; then - eval $cmd_loop -elif [[ "$1" == "-l" ]]; then - eval $cmd_loop -elif [[ "$1" == "--loop" ]]; then - eval $cmd_loop -elif [[ "$1" == "render" ]]; then - eval $cmd_render -elif [[ "$1" == "visualize" ]]; then - eval $cmd_render -else - eval $cmd_single -fi +function show_version { + echo "${0##*/} version $version" + echo "Licensed under the GNU Public License, v3+" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://gitlab.com/admesg/dotfiles" +} + +function die { + printf '%s\n' "$1" >&2 + exit 1 +} + +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -n|--interval) + loopinterval="$2" + shift + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift +done + +for cmd in "$@"; do + case "$cmd" in + loop) + julia --color=yes -e "import Granular; Granular.status(loop=true, t_int=$loopinterval)" + exit 0 + ;; + visualize) + julia --color=yes -e "import Granular; Granular.status(visualize=true)" + exit 0 + ;; + *) + die 'Unknown commmand specified' + ;; + esac +done +julia --color=yes -e "import Granular; Granular.status()"