From 9014d0a70692bc4c80371a1a0bbb7f7fe293f2c2 Mon Sep 17 00:00:00 2001
From: Pekka Helenius <pekka.helenius@fjordtek.com>
Date: Sat, 8 Feb 2025 11:49:36 +0200
Subject: [PATCH] Add a profile.d snippet for PATH configuration

---
 profile.d/01-user-path.sh | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 profile.d/01-user-path.sh

diff --git a/profile.d/01-user-path.sh b/profile.d/01-user-path.sh
new file mode 100644
index 0000000..e4e1750
--- /dev/null
+++ b/profile.d/01-user-path.sh
@@ -0,0 +1,42 @@
+# Add user-specific path definitions to PATH
+# variable. Set only unique values to PATH,
+# keeping current order.
+#
+# NOTE: Refer to your distribution documentation
+# regarding to behavior of shell environment and
+# sourcing of /etc/profile & /etc/profile.d/* files
+# when using shell non-interactively.
+
+[ -z "${HOME}" ] && return 0
+[ -z "${PATH}" ] && return 0
+[ -n "${__PATH}" ] && return 0
+[ -n "${__USER_PATHS}" ] && return 0
+command -v -p awk >/dev/null 2>&1 || return 0
+
+__USER_PATHS="${HOME}/.local/bin"
+
+__PATH=$(awk -v __path="${__USER_PATHS}:${PATH}" '
+  BEGIN {
+
+    # Store individual values of environment variable
+    # __PATH into local variable "paths". Split by using
+    # character ":".
+    split(__path,paths,":");
+
+    # For each value in paths, print the value if
+    # not already stored in map variable "a",
+    # and length of the value is greater than zero.
+    for (i=0; i<length(paths); i++) {
+      if (!a[paths[i]] && length(paths[i]) > 0) {
+        a[paths[i]] = "seen";
+        printf "%s%s", sep, paths[i];
+        sep=":";
+      }
+    }
+
+  }
+')
+
+export PATH="${__PATH}"
+
+unset __PATH __USER_PATHS