From 4830c705bd80ed7f3a7a8dac3aecc2386bb42307 Mon Sep 17 00:00:00 2001 From: Tomasz Kostrzewa Date: Wed, 6 Mar 2024 19:13:26 +0100 Subject: [PATCH] modified: RdzeN-Profile.ps1 --- RdzeN-Profile.ps1 | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/RdzeN-Profile.ps1 b/RdzeN-Profile.ps1 index 79c765a..8e2c102 100644 --- a/RdzeN-Profile.ps1 +++ b/RdzeN-Profile.ps1 @@ -2,6 +2,7 @@ # # Example Powershell Profile. # + # 1. Check if GITEA folder exists. $path_gitea = "$($env:USERPROFILE)\GITEA" $path_gitea_powershell_profile = "$path_gitea\PowerShell-Profile" @@ -17,62 +18,65 @@ if (-not (Test-Path $path_gitea_powershell_profile_functions)) { New-Item -ItemType Directory -Path $path_gitea_powershell_profile_functions | Out-Null } -# 2. Check if local repo is up to date GIT REPO +# 2. Check if local GIT repo is up to date Set-Location $path_gitea_powershell_profile $RepositoryURL = "https://gitea.rdzen.net/najlepszytomasz/PowerShell-Profile.git" try { $git_tmp = git fetch origin - Write-Host "Success GIT git fetch origin: $RepositoryURL" -ForegroundColor Green + Write-Host "Success + git fetch origin + : $RepositoryURL" -ForegroundColor Green } catch { - Write-Host "Error occurred while GIT git fetch origin: $RepositoryURL" -ForegroundColor Red + Write-Host "Error occurred while git fetch origin + : $RepositoryURL" -ForegroundColor Red } try { $git_tmp = git status - Write-Host "Success GIT git status: $RepositoryURL" -ForegroundColor Green + Write-Host "Success + git status + : $RepositoryURL" -ForegroundColor Green } catch { - Write-Host "Error occurred while GIT git status: $RepositoryURL" -ForegroundColor Red + Write-Host "Error occurred while git status + : $RepositoryURL" -ForegroundColor Red } # 3. Download GIT REPO -$git_repo_update = $null -# Function to pull repository function Pull-Repository { Set-Location $path_gitea_powershell_profile try { git pull -q - Write-Host "Success GIT pull for: $RepositoryURL" -ForegroundColor Green + Write-Host "Success + git pull + : $RepositoryURL" -ForegroundColor Green } catch { - Write-Host "Error occurred while GIT pull for: $RepositoryURL" -ForegroundColor Red + Write-Host "Error occurred while git pull for: $RepositoryURL" -ForegroundColor Red } } if ($git_tmp -match "(Your branch is up to date)") { $git_tmp | ForEach-Object { Write-Host $_ -ForegroundColor Green - $git_repo_update = $false } } else { $git_tmp | ForEach-Object { Write-Host $_ -ForegroundColor Red } - $git_repo_update = $true Pull-Repository } # 4. List functions $path_to_search = "$path_gitea_powershell_profile_functions\*" $found_functions = @() -# Szukanie funkcji w plikach Get-ChildItem $path_to_search | ForEach-Object { $file_content = Get-Content $_.FullName -Raw $matches = [Regex]::Matches($file_content, '(?<=function\s).*?(?={)') foreach ($match in $matches) { $found_functions += $match.Value.Trim() } + # 4.5 Load functions . $_ } - $found_functions = $found_functions | Sort-Object for ($i = 0; $i -lt $found_functions.Count; $i++) { @@ -80,13 +84,16 @@ for ($i = 0; $i -lt $found_functions.Count; $i++) { Write-Host ")`t" -NoNewline -ForegroundColor Blue Write-Host "$($found_functions[$i])" -ForegroundColor Cyan } +# 5. Check if current Profile is equal to repo profile file. +$profile_repo = Get-Content "$path_gitea_powershell_profile\RdzeN-Profile.ps1" +$profile_system = Get-Content $PROFILE -if ($git_repo_update -eq $true) { +$compare_profile = Compare-Object -ReferenceObject $profile_repo -DifferenceObject $profile_system +# 6. Override actual profile and reload it. +if ($compare_profile.sideindicator.count -gt 0) { Override-Profile Reload-Profile } # 99. Prompt profile loaded New-SimulateTyping "PowerShell User Profile is loaded" -# -# \ No newline at end of file