From b9b192c42a2d57f2adfb44ab88e39b9c7c6ba1ed Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sat, 24 Aug 2024 00:42:57 +0200
Subject: [PATCH] Update `aliae` configuration script

---
 scripts/Common/Software/aliae/main.fish | 31 +++++++++++++++----------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/scripts/Common/Software/aliae/main.fish b/scripts/Common/Software/aliae/main.fish
index fe039087..3ce13c2b 100755
--- a/scripts/Common/Software/aliae/main.fish
+++ b/scripts/Common/Software/aliae/main.fish
@@ -10,28 +10,35 @@ begin
     function configureSW -V dir
         source "$dir/../bash/profile.fish"
         source "$dir/../fish/profile.fish"
-        set -l file /etc/aliae/aliae.yml
-        echo "export ALIAE_CONFIG=$(string escape "$file")" | sudo tee /etc/profile.d/aliae.sh > /dev/null
+        set -l file (pwsh -CommandWithArgs '. $args[0]; Get-GlobalConfigPath' "$dir/Constants.ps1");
         sudo install -Dm644 "$dir/aliae.yml" "$file"
 
         begin
             printf %s\n \
-                "# aliae" \
-                'eval "$(aliae init bash)"' \
+                "if [ -f $(string escape $file) ]" \
+                'then' \
+                "  eval \"\$(aliae init bash --config $(string escape $file))\"" \
+                'fi' \
+                '' \
+                'if [ -n "$ALIAE_CONFIG" ] && [ -f "$ALIAE_CONFIG" ] || [ -f ~/.aliae.yaml ]' \
+                'then' \
+                '  eval "$(aliae init bash)"' \
+                'fi' \
+                '' \
                 'eval "$(aliae completion bash)"'
         end | installBashProfile "aliae" "aliae"
 
-        begin
-            printf %s\n "" \
-                "# aliae" \
-                'eval "$(aliae init bash)"' \
-                'eval "$(aliae completion bash)"'
-        end | sudo tee /etc/skel/.bashrc > /dev/null
-
         if type -q fish
             begin
                 printf %s\n \
-                    "aliae init fish | source" \
+                    "if [ -f $(string escape $file) ]" \
+                    "  eval \"\$(aliae init bash --config $(string escape $file))\"" \
+                    'end' \
+                    '' \
+                    'if [ -n "$ALIAE_CONFIG" ] && [ -f "$ALIAE_CONFIG" ] || [ -f ~/.aliae.yaml ]' \
+                    '  aliae init fish | source' \
+                    'end' \
+                    '' \
                     "aliae completion fish | source"
             end | installFishProfile "aliae" "aliae"
         end