# gitea.RdzeN.net # # Example Powershell Profile. # # 1. Check if GITEA folder exists. $path_gitea = "$($env:USERPROFILE)\GITEA" $path_gitea_powershell_profile = "$path_gitea\PowerShell-Profile" $path_gitea_powershell_profile_functions = "$path_gitea_powershell_profile\functions" if (-not (Test-Path $path_gitea)) { New-Item -ItemType Directory -Path $path_gitea | Out-Null } if (-not (Test-Path $path_gitea_powershell_profile)) { New-Item -ItemType Directory -Path $path_gitea_powershell_profile | Out-Null } if (-not (Test-Path $path_gitea_powershell_profile_functions)) { New-Item -ItemType Directory -Path $path_gitea_powershell_profile_functions | Out-Null } # 2. Download / pull GIT REPO $RepositoryURL = "https://gitea.rdzen.net/najlepszytomasz/PowerShell-Profile.git" # Define paths $path_gitea = "$($env:USERPROFILE)\GITEA" $path_gitea_powershell_profile = "$path_gitea\PowerShell-Profile" $path_gitea_powershell_profile_functions = "$path_gitea_powershell_profile\functions" $path_profile_file = "$path_gitea_powershell_profile\RdzeN-Profile.ps1" # 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 } catch { Write-Host "Error occurred while GIT pull for: $RepositoryURL" -ForegroundColor Red } } # Check if the profile file exists locally if (-not (Test-Path $path_profile_file)) { Write-Host "Profile file not found locally. Pulling from repository..." -ForegroundColor Yellow Pull-Repository Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object { . $_.FullName } # 97. Override profile Override-Profile # 98. Override profile #Reload-Profile } else { # Check if the profile file has been modified $local_profile_hash = Get-FileHash -Path $path_profile_file -Algorithm SHA1 # Dodaj nagłówek do lokalnego hasha $local_profile_hash_with_header = "blob $($local_profile_hash.Length)`0" + (Get-Content $path_profile_file -Raw) $local_profile_hash_with_header = Get-FileHash -Algorithm SHA1 -InputStream ([System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($local_profile_hash_with_header))) $remote_profile_hash = & git hash-object $path_profile_file if ($local_profile_hash_with_header.Hash.ToLower() -ne $remote_profile_hash.Trim()) { Write-Host "Local profile file has been modified. Pulling from repository..." -ForegroundColor Yellow Pull-Repository Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object { . $_.FullName } # 97. Override profile Override-Profile # 98. Override profile #Reload-Profile } else { Write-Host "Local profile file is up to date." -ForegroundColor Green } } # Check if functions have been modified $local_functions_hashes = @{} $remote_functions_hashes = @{} # Iterate through local functions Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object { $local_functions_hashes[$_.Name] = (Get-FileHash -Path $_.FullName -Algorithm SHA1).Hash } # Get remote functions hashes Set-Location $path_gitea_powershell_profile_functions git pull -q Get-ChildItem | ForEach-Object { $remote_functions_hashes[$_.Name] = (git hash-object $_.Name).Trim() } # Compare local and remote function hashes $functions_to_pull = @() foreach ($function_name in $local_functions_hashes.Keys) { if ($local_functions_hashes[$function_name] -ne $remote_functions_hashes[$function_name]) { $functions_to_pull += $function_name } } if ($functions_to_pull.Count -gt 0) { Write-Host "Functions have been modified. Pulling from repository..." -ForegroundColor Yellow Pull-Repository Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object { . $_.FullName } } else { Write-Host "Functions are up to date." -ForegroundColor Green } # 4. List functions # Lokalizacja plików $path_to_search = "$path_gitea_powershell_profile_functions\*" # Zmienna do przechowywania wyników $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() } } $found_functions = $found_functions | Sort-Object for ($i = 0; $i -lt $found_functions.Count; $i++) { Write-Host "$($i+1)" -NoNewline -ForegroundColor Cyan Write-Host ")`t" -NoNewline -ForegroundColor Blue Write-Host "$($found_functions[$i])" -ForegroundColor Cyan } # 99. Prompt profile loaded New-SimulateTyping "PowerShell User Profile is loaded" #