improvements for sanitized username
authorFred Hamster <fred@gruntose.com>
Mon, 16 Dec 2024 20:44:24 +0000 (15:44 -0500)
committerFred Hamster <fred@gruntose.com>
Mon, 16 Dec 2024 20:44:24 +0000 (15:44 -0500)
saves value in an exported variable so not calling sed on every usage.

scripts/core/variables.sh

index b0bc95a6564f9fbc8400d32768e426cf53927dd4..9b535889b986742c1471c8c5dca6510ac6c8a050 100644 (file)
@@ -40,8 +40,13 @@ return 0
 
   # a handy helper method that turns a potentially gross USER variable into
   # a nice clean one (by removing email domains).
+  export SANITIZED_USER=""
   function sanitized_username() {
-    echo $USER | sed -e 's/@[a-zA-Z0-9_.]*//'
+    if [ ! -z "$SANITIZED_USER" ]; then
+      echo -n "$SANITIZED_USER"
+    fi
+    export SANITIZED_USER="$(echo "$USER" | sed -e 's/@[a-zA-Z0-9_.]*//')"
+    echo -n "$SANITIZED_USER"
   }
 
 ##############