From 638d2419730d15fe68b9c84071961974c8aa4949 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Wed, 20 Mar 2024 16:00:44 +0100
Subject: [PATCH] Add aliae to all OSes

---
 scripts/Arch/Software/aliae/install.sh     | 10 ++++++++
 scripts/Common/Config/aliae/aliae.yml      | 16 ++++++++++++
 scripts/Common/Config/aliae/install.sh     | 29 ++++++++++++++++++++++
 scripts/Windows/Config/aliae/Install.ps1   | 21 ++++++++++++++++
 scripts/Windows/Software/aliae/Install.ps1 |  7 ++++++
 5 files changed, 83 insertions(+)
 create mode 100755 scripts/Arch/Software/aliae/install.sh
 create mode 100644 scripts/Common/Config/aliae/aliae.yml
 create mode 100755 scripts/Common/Config/aliae/install.sh
 create mode 100644 scripts/Windows/Config/aliae/Install.ps1
 create mode 100644 scripts/Windows/Software/aliae/Install.ps1

diff --git a/scripts/Arch/Software/aliae/install.sh b/scripts/Arch/Software/aliae/install.sh
new file mode 100755
index 00000000..431a72e9
--- /dev/null
+++ b/scripts/Arch/Software/aliae/install.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+pushd "${BASH_SOURCE%/*}" > /dev/null;
+
+yay --noconfirm -Syu \
+    aliae-bin \
+    ;
+
+. "../../../Common/Config/aliae/install.sh";
+
+popd > /dev/null;
diff --git a/scripts/Common/Config/aliae/aliae.yml b/scripts/Common/Config/aliae/aliae.yml
new file mode 100644
index 00000000..27909f62
--- /dev/null
+++ b/scripts/Common/Config/aliae/aliae.yml
@@ -0,0 +1,16 @@
+alias: []
+env: []
+path: []
+script:
+  - value: |
+      [ -f /bash/conf.d/* ] && . /bash/conf.d/* || true
+    if: match .Shell "bash"
+  - value: |
+      # Profile Files
+      $profileRoot = Split-Path -Parent $PROFILE;
+      $profilePath = "$profileRoot/profile.d/*.ps1";
+
+      if (Test-Path $profilePath) {
+          Get-Item $profilePath | ForEach-Object { . $_; };
+      }
+    if: match .Shell "pwsh"
diff --git a/scripts/Common/Config/aliae/install.sh b/scripts/Common/Config/aliae/install.sh
new file mode 100755
index 00000000..b88502ce
--- /dev/null
+++ b/scripts/Common/Config/aliae/install.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+SKIP_POWERSHELL=${SKIP_POWERSHELL:-0};
+pushd "${BASH_SOURCE%/*}" > /dev/null;
+
+. "../../Scripts/is-truthy.sh";
+
+if ! grep "\baliae\b" ~/.bashrc > /dev/null
+then
+    {
+        echo '# aliae';
+        echo 'eval "$(aliae init bash)"';
+        echo "";
+    } >> ~/.bashrc;
+fi;
+
+if ! isTruthy "${SKIP_POWERSHELL}"
+then
+    profileFile="$(pwsh -c '$PROFILE')";
+
+    if [ ! -f "$profileFile" ] || grep "\baliae\b" "$profileFile" > /dev/null
+    then
+        install -dm755 "$(dirname "$profileFile")";
+        echo "aliae init pwsh | Invoke-Expression" >> "$profileFile";
+    fi;
+fi;
+
+echo 'aliae init fish | source' | sudo tee /etc/fish/conf.d/aliae.fish > /dev/null;
+cp aliae.yml ~/.aliae.yaml;
+popd > /dev/null;
diff --git a/scripts/Windows/Config/aliae/Install.ps1 b/scripts/Windows/Config/aliae/Install.ps1
new file mode 100644
index 00000000..162db799
--- /dev/null
+++ b/scripts/Windows/Config/aliae/Install.ps1
@@ -0,0 +1,21 @@
+#!/bin/pwsh
+param($context);
+. "$PSScriptRoot/../../Scripts/Context.ps1";
+
+[Context] $context = $context;
+$script = New-TemporaryFile;
+$script = Rename-Item $script "$($script.Name).sh" -PassThru;
+
+Write-Information "Preparing setup script";
+
+Set-Content $script (
+    [string]::Join(
+        "`n",
+        @(
+            "SKIP_POWERSHELL=1 bash `"$PSScriptRoot/../../../Common/Config/aliae/install.sh`"",
+            "rm ~/.bashrc")));
+
+$context.AddPowerShellProfileStatement("# aliae`naliae init pwsh | Invoke-Expression");
+Write-Information "Running prepared script";
+Start-Process -Wait $script;
+Remove-Item $script;
\ No newline at end of file
diff --git a/scripts/Windows/Software/aliae/Install.ps1 b/scripts/Windows/Software/aliae/Install.ps1
new file mode 100644
index 00000000..bbc7422a
--- /dev/null
+++ b/scripts/Windows/Software/aliae/Install.ps1
@@ -0,0 +1,7 @@
+#!/bin/pwsh
+param($context);
+. "$PSScriptRoot/../../Scripts/Context.ps1";
+
+[Context] $context = $context;
+winget install --accept-source-agreements --accept-package-agreements -s winget --scope machine -e --id JanDeDobbeleer.Aliae;
+. "$PSScriptRoot/../../Config/Aliae/Install.ps1" $context;