modified: RdzeN-Profile.ps1
This commit is contained in:
parent
fa4d6a45a7
commit
4830c705bd
@ -2,6 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Example Powershell Profile.
|
# Example Powershell Profile.
|
||||||
#
|
#
|
||||||
|
|
||||||
# 1. Check if GITEA folder exists.
|
# 1. Check if GITEA folder exists.
|
||||||
$path_gitea = "$($env:USERPROFILE)\GITEA"
|
$path_gitea = "$($env:USERPROFILE)\GITEA"
|
||||||
$path_gitea_powershell_profile = "$path_gitea\PowerShell-Profile"
|
$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
|
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
|
Set-Location $path_gitea_powershell_profile
|
||||||
$RepositoryURL = "https://gitea.rdzen.net/najlepszytomasz/PowerShell-Profile.git"
|
$RepositoryURL = "https://gitea.rdzen.net/najlepszytomasz/PowerShell-Profile.git"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$git_tmp = git fetch origin
|
$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 {
|
} 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 {
|
try {
|
||||||
$git_tmp = git status
|
$git_tmp = git status
|
||||||
Write-Host "Success GIT git status: $RepositoryURL" -ForegroundColor Green
|
Write-Host "Success
|
||||||
|
git status
|
||||||
|
: $RepositoryURL" -ForegroundColor Green
|
||||||
} catch {
|
} 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
|
# 3. Download GIT REPO
|
||||||
$git_repo_update = $null
|
|
||||||
# Function to pull repository
|
|
||||||
function Pull-Repository {
|
function Pull-Repository {
|
||||||
Set-Location $path_gitea_powershell_profile
|
Set-Location $path_gitea_powershell_profile
|
||||||
try {
|
try {
|
||||||
git pull -q
|
git pull -q
|
||||||
Write-Host "Success GIT pull for: $RepositoryURL" -ForegroundColor Green
|
Write-Host "Success
|
||||||
|
git pull
|
||||||
|
: $RepositoryURL" -ForegroundColor Green
|
||||||
} catch {
|
} 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)") {
|
if ($git_tmp -match "(Your branch is up to date)") {
|
||||||
$git_tmp | ForEach-Object {
|
$git_tmp | ForEach-Object {
|
||||||
Write-Host $_ -ForegroundColor Green
|
Write-Host $_ -ForegroundColor Green
|
||||||
$git_repo_update = $false
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$git_tmp | ForEach-Object {
|
$git_tmp | ForEach-Object {
|
||||||
Write-Host $_ -ForegroundColor Red
|
Write-Host $_ -ForegroundColor Red
|
||||||
}
|
}
|
||||||
$git_repo_update = $true
|
|
||||||
Pull-Repository
|
Pull-Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
# 4. List functions
|
# 4. List functions
|
||||||
$path_to_search = "$path_gitea_powershell_profile_functions\*"
|
$path_to_search = "$path_gitea_powershell_profile_functions\*"
|
||||||
$found_functions = @()
|
$found_functions = @()
|
||||||
# Szukanie funkcji w plikach
|
|
||||||
Get-ChildItem $path_to_search | ForEach-Object {
|
Get-ChildItem $path_to_search | ForEach-Object {
|
||||||
$file_content = Get-Content $_.FullName -Raw
|
$file_content = Get-Content $_.FullName -Raw
|
||||||
$matches = [Regex]::Matches($file_content, '(?<=function\s).*?(?={)')
|
$matches = [Regex]::Matches($file_content, '(?<=function\s).*?(?={)')
|
||||||
foreach ($match in $matches) {
|
foreach ($match in $matches) {
|
||||||
$found_functions += $match.Value.Trim()
|
$found_functions += $match.Value.Trim()
|
||||||
}
|
}
|
||||||
|
# 4.5 Load functions
|
||||||
. $_
|
. $_
|
||||||
}
|
}
|
||||||
|
|
||||||
$found_functions = $found_functions | Sort-Object
|
$found_functions = $found_functions | Sort-Object
|
||||||
|
|
||||||
for ($i = 0; $i -lt $found_functions.Count; $i++) {
|
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 ")`t" -NoNewline -ForegroundColor Blue
|
||||||
Write-Host "$($found_functions[$i])" -ForegroundColor Cyan
|
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
|
Override-Profile
|
||||||
Reload-Profile
|
Reload-Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
# 99. Prompt profile loaded
|
# 99. Prompt profile loaded
|
||||||
New-SimulateTyping "PowerShell User Profile is loaded"
|
New-SimulateTyping "PowerShell User Profile is loaded"
|
||||||
#
|
|
||||||
#
|
|
Loading…
x
Reference in New Issue
Block a user