summaryrefslogtreecommitdiffstats
path: root/pkgs/stdenv/generic
diff options
context:
space:
mode:
authorLily Ballard <lily@sb.org>2019-08-05 21:27:21 -0700
committerFrederik Rietdijk <freddyrietdijk@fridh.nl>2019-11-12 14:38:41 +0100
commitd45d6205de2e41b99405efae1066d36dcff71fbd (patch)
tree1d995de4279e7cffacccec571bbe2d5af9851c65 /pkgs/stdenv/generic
parentd688c7cd05b155e223e478b6e6bda97737d1441b (diff)
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.
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r--pkgs/stdenv/generic/setup.sh11
1 files changed, 7 insertions, 4 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 730e77c20f90..5b8fdde57961 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -787,14 +787,17 @@ dumpVars() {
# Utility function: echo the base name of the given path, with the
# prefix `HASH-' removed, if present.
stripHash() {
- local strippedName
+ local strippedName casematchOpt=0
# On separate line for `set -e`
- strippedName="$(basename "$1")"
- if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
- echo "$strippedName" | cut -c34-
+ strippedName="$(basename -- "$1")"
+ shopt -q nocasematch && casematchOpt=1
+ shopt -u nocasematch
+ if [[ "$strippedName" =~ ^[a-z0-9]{32}- ]]; then
+ echo "${strippedName:33}"
else
echo "$strippedName"
fi
+ if (( casematchOpt )); then shopt -s nocasematch; fi
}