modified: RdzeN-Profile.ps1
This commit is contained in:
parent
fa4d6a45a7
commit
4830c705bd
@ -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"
|
||||
#
|
||||
#
|
Loading…
x
Reference in New Issue
Block a user