91 lines
2.8 KiB
PowerShell
91 lines
2.8 KiB
PowerShell
# 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. Check if local repo is up to date GIT REPO
|
|
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
|
|
} catch {
|
|
Write-Host "Error occurred while GIT git fetch origin: $RepositoryURL" -ForegroundColor Red
|
|
}
|
|
try {
|
|
$git_tmp = git status
|
|
Write-Host "Success GIT git status: $RepositoryURL" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "Error occurred while GIT 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
|
|
} catch {
|
|
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()
|
|
}
|
|
}
|
|
|
|
if ($git_repo_update -eq $true) {
|
|
Override-Profile
|
|
Reload-Profile
|
|
}
|
|
|
|
$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"
|
|
#
|
|
# |