CONFIG: handle string splitting [zsh] (#2640)

This commit is contained in:
Mark Olesen
2022-11-22 18:03:16 +01:00
parent a8b0ec0c4e
commit d5e82f072e

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com # \\ / A nd | www.openfoam.com
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd. # Copyright (C) 2018-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -212,7 +212,7 @@ then
findLibrary() findLibrary()
{ {
local prefixDir localDir searchDir searchName local prefixDir localDir searchDir searchName
local file ext local file found ext zshsplit
searchDir=true searchDir=true
@ -264,6 +264,15 @@ then
## echo "search: $# $@" 1>&2 ## echo "search: $# $@" 1>&2
# Split extLibraries on space: zsh needs shwordsplit for that
if [ -n "$ZSH_VERSION" ]
then
# $- contains 'y' if shwordsplit already active
zshsplit=1
case "$-" in (*y*) unset zshsplit;; esac
setopt shwordsplit
fi
for searchDir in "$@" for searchDir in "$@"
do do
[ -n "$searchDir" ] || continue [ -n "$searchDir" ] || continue
@ -272,8 +281,8 @@ then
file="$prefixDir/$searchDir/$searchName$ext" file="$prefixDir/$searchDir/$searchName$ext"
if [ -f "$file" ] && [ -r "$file" ] if [ -f "$file" ] && [ -r "$file" ]
then then
echo "$file" # Found found="$file" # Found
return 0 break 2
fi fi
done done
done done
@ -281,6 +290,15 @@ then
else else
# Directed search # Directed search
# Split extLibraries on space: zsh needs shwordsplit for that
if [ -n "$ZSH_VERSION" ]
then
# $- contains 'y' if shwordsplit already active
zshsplit=1
case "$-" in (*y*) unset zshsplit;; esac
setopt shwordsplit
fi
for file for file
do do
[ -n "$file" ] || continue [ -n "$file" ] || continue
@ -288,13 +306,25 @@ then
do do
if [ -f "$file$ext" ] && [ -r "$file$ext" ] if [ -f "$file$ext" ] && [ -r "$file$ext" ]
then then
echo "$file$ext" # Found found="$file$ext" # Found
return 0 break 2
fi fi
done done
done done
fi fi
# Restore old shwordsplit (zsh)
if [ -n "$zshsplit" ]
then
unsetopt shwordsplit
fi
if [ -n "$found" ]
then
echo "$found"
return 0
fi
return 2 return 2
} }