From c9e4fd77fd78671ff8b634e678e8b08f5393e065 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Thu, 23 Feb 2017 12:48:43 +0100 Subject: [PATCH] ENH: add options for foamEtcFile and shell evaluation - Eg, instead if file=$(foamEtcFile filename) then . $file fi can write eval "$(foamEtcFile -sh filename)" Also supports -verbose reporting, which is especially useful for csh, since it allows simplification of aliases and allows the message to land on stderr instead of stdout. eval `foamEtcFile -csh -verbose filename` --- bin/foamEtcFile | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index 70fdb6caf81..9ea5b73f7d4 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -58,8 +58,12 @@ options: -m, -mode MODE any combination of u(user), g(group), o(other) -p, -prefix DIR specify an alternative installation prefix -q, -quiet suppress all normal output - -s, -silent suppress all stderr output - -v, -version VER specify an alternative OpenFOAM version (eg, 3.0, 1612, ...) + -s, -silent suppress stderr output, except for things that are emitted + by -csh-verbose, -sh-verbose. + -v, -version VER specify alternative OpenFOAM version (eg, 3.0, 1612, ...) + -csh | -sh produce output suitable for a csh or sh 'eval' + -csh-verbose, + -sh-verbose with additional verbosity -help print the usage Locate user/group/shipped file with semantics similar to the @@ -124,7 +128,7 @@ esac # Default mode is always 'ugo' mode=ugo -unset optAll optList +unset optAll optList optShell # parse options while [ "$#" -gt 0 ] @@ -135,9 +139,15 @@ do ;; -a | -all) optAll=true + unset optShell ;; -l | -list) optList=true + unset optShell + ;; + -csh | -sh | -csh-verbose | -sh-verbose) + optShell="${1#-}" + unset optAll ;; -mode=[ugo]*) mode="${1#-mode=}" @@ -209,7 +219,6 @@ else projectDir="$prefixDir/${WM_PROJECT:-OpenFOAM}-$version" # standard fi - # debugging: # echo "Installed locations:" # for i in projectDir prefixDir projectDirName version versionNum @@ -256,7 +265,7 @@ then [ "$nArgs" -le 1 ] || usage # a silly combination, but -quiet does have precedence - [ "$optQuiet" = true ] && exit 0 + [ -n "$optQuiet" ] && exit 0 for dir do @@ -280,10 +289,28 @@ else if [ -f "$dir/$fileName" ] then exitCode=0 - [ "$optQuiet" = true ] && break - - echo "$dir/$fileName" - [ "$optAll" = true ] || break + [ -n "$optQuiet" ] && break + + case "$optShell" in + (*verbose) + echo "Using: $dir/$fileName" 1>&2 + ;; + esac + + case "$optShell" in + csh*) + echo "source $dir/$fileName" + break + ;; + sh*) + echo ". $dir/$fileName" + break + ;; + *) + echo "$dir/$fileName" + [ -n "$optAll" ] || break + ;; + esac fi done -- GitLab