mrklein / openfoam-os-x

Patches for OpenFOAM(R) to build it on OS X
93 stars 33 forks source link

Adding zsh support #60

Closed BrushXue closed 3 years ago

BrushXue commented 3 years ago

Now zsh is the default shell in macOS. And the original OpenFOAM config.sh should be zsh compatible, as documented in https://develop.openfoam.com/Development/openfoam/-/blob/master/bin/foamSystemCheck#L115 In your v2012 patch(also applies to previous patches), regarding the file etc/config.sh/mac/paraview

    paraview () {
        local _paraviews=(/Applications/[Pp][Aa][Rr][Aa][Vv][Ii][Ee][Ww]*.app)
        $_paraviews/Contents/MacOS/paraview "$@"
    }

    export -f paraview

zsh doesn't support export -f. It will only print the function to the terminal.

What I'm doing right now is commenting out these lines, and adding them to the beginning of bin/paraFoam without export -f. This temporary fix is really ugly. Do you have any better idea to implement a universal script that works on both shells? Thanks.

BrushXue commented 3 years ago

Sorry I didn't notice there is a similar issue #56. So it seems like there's no solution to support both shells. Maybe I'll just keep this for my personal use. Switching to zsh or a newer bash from homebrew, which one is better?

mrklein commented 3 years ago

Work-around could be to detect if paraview file is sourced under zsh and this could be achieved with:

    if [ -n "$ZSH_VERSION" ]
    then
        # ZSH does not have -f flag
        export paraview
    else
        export -f paraview
    fi

Yet, this work-around will not export function to sub-shells, so certain functionality will be broken (ex. running paraview from scripts). But it will remove annoying function output.

Answering your second question: it depends on the definition of better. For my use-cases old bash is good enough, so it is better, because I do not need to change anything. Guess, there are people, who prefer tcsh. For someone zsh is better.

BrushXue commented 3 years ago

The worst part of the outdated bash is auto completion. I would prefer updating bash to have best compatibility with Linux, only if Apple allows us to touch /bin/bash.🙃