I'm having a small problem with folding and unfolding things in VSCode shellscript code. When I write a function and add a help section to it, with a heredoc that ends in EOF, naturally - After this, when I fold the function from next to the function name, it folds down until the EOF text, nothing else. The EOF can be further folded to hide most of the function, but this is really getting on my nerves.
I use regions a lot aswell, since I'm used to those, but they also break from EOF.
Is the only way to stop using heredocs/nowdocs, or is there a way to fix this?
Thanks in advance - Included two screenshots, one unfolded, and the other one folded, and as you can see, EOF stops the folding.
I tried to fold a function in Shellscript language file, but if there is "EOF", "EOL" or similar (end to a here/nowdoc), the folding folds only up to that point and no further.
(Screenshot) Unfolded Code (Screenshot) Code Folded Until EOF
UPDATE: Here is the code as is, instead of screenshots:
_validate_input() {
# If -h|--help specified or no args provided, output help information.
if [[ $# -lt 2 || $@ =~ '(^-h| -h|--help$|--help |^-[[:alnum:]]*h| -[[:alnum:]]*h)' ]]; then
cat <<-EOF && return 0
$funcstack[1] - Query an input string from the user.
Usage: $funcstack[1] [INPUT] [VALIDATION_TYPE]
INPUT
Input string to validate.
VALIDATION_TYPE
Type to validate; Currently available: "name", "email".
EOF
fi
local input="$1" # Get input from first argument.
local valtype="$2" # Get validation type from second argument.
# Ensure validation type value is valid.
if [[ $valtype == 'email' ]]; then
# Check that input is a valid email.
if echo $input | pcre2grep '^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$' | read input_checked; then
return 0
else
printf "\e[31;1mError: Invalid email "%s". (Matched against: \$'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\$').\e[0m\n" "$input" >&2
return 1
fi
elif [[ $valtype == 'name' ]]; then
# Check that input is a valid name.
if echo $input | pcre2grep $'^[A-Z][a-zA-Z \'.-]*((?![0-9])[^-])$' | read input_checked; then
return 0
else
printf "\e[31;1mError: Invalid name "%s" (Matched against: \$'^[A-Z][a-zA-Z \'.-]*((?![0-9])[^-])$').\e[0m\n" "$input" >&2
return 1
fi
else
printf '\e[31;1mError in _validate_input(): validation type value "%s" is invalid; Must be "name" or "email".\e[0m\n' "$valtype" >&2
return 1
fi
}
That code, when folded in my IDE, folds from the function name until EOF.
<<-EOF
as opposed to<<EOF
, as long as you're using tabs and not spaces for indentation, you should be able to indent theEOF
sigil to hint to the editor how to handle folding. You will need to reconfigure the editor into tabbed mode, though, if it's not already configured appropriately.cat
when you can useprintf
?