setup.sh: rewrite stripHash
Rewrite the `stripHash` helper function with 2 differences: * Paths starting with `--` will no longer produce an error. * Use Bash string manipulation instead of shelling out to `grep` and `cut`. This should be faster.
This commit is contained in:
parent
d688c7cd05
commit
d45d6205de
@ -787,14 +787,17 @@ dumpVars() {
|
|||||||
# Utility function: echo the base name of the given path, with the
|
# Utility function: echo the base name of the given path, with the
|
||||||
# prefix `HASH-' removed, if present.
|
# prefix `HASH-' removed, if present.
|
||||||
stripHash() {
|
stripHash() {
|
||||||
local strippedName
|
local strippedName casematchOpt=0
|
||||||
# On separate line for `set -e`
|
# On separate line for `set -e`
|
||||||
strippedName="$(basename "$1")"
|
strippedName="$(basename -- "$1")"
|
||||||
if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
|
shopt -q nocasematch && casematchOpt=1
|
||||||
echo "$strippedName" | cut -c34-
|
shopt -u nocasematch
|
||||||
|
if [[ "$strippedName" =~ ^[a-z0-9]{32}- ]]; then
|
||||||
|
echo "${strippedName:33}"
|
||||||
else
|
else
|
||||||
echo "$strippedName"
|
echo "$strippedName"
|
||||||
fi
|
fi
|
||||||
|
if (( casematchOpt )); then shopt -s nocasematch; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user