Initial commit

This commit is contained in:
Fabio Scotto di Santolo
2025-07-25 11:02:18 +02:00
commit 6249ebcb1f
73 changed files with 12227 additions and 0 deletions

View File

@@ -0,0 +1,245 @@
# set PowerShell to UTF-8
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
function Clear-Cache {
# add clear cache logic here
Write-Host "Clearing cache..." -ForegroundColor Cyan
# Clear Windows Prefetch
Write-Host "Clearing Windows Prefetch..." -ForegroundColor Yellow
Remove-Item -Path "$env:SystemRoot\Prefetch\*" -Force -ErrorAction SilentlyContinue
# Clear Windows Temp
Write-Host "Clearing Windows Temp..." -ForegroundColor Yellow
Remove-Item -Path "$env:SystemRoot\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear User Temp
Write-Host "Clearing User Temp..." -ForegroundColor Yellow
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear Internet Explorer Cache
Write-Host "Clearing Internet Explorer Cache..." -ForegroundColor Yellow
Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\INetCache\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Cache clearing completed." -ForegroundColor Green
}
# Utility Functions
function Test-CommandExists {
param($command)
$exists = $null -ne (Get-Command $command -ErrorAction SilentlyContinue)
return $exists
}
# Editor Configuration
$EDITOR = if (Test-CommandExists nvim) { 'nvim' }
elseif (Test-CommandExists pvim) { 'pvim' }
elseif (Test-CommandExists vim) { 'vim' }
elseif (Test-CommandExists vi) { 'vi' }
elseif (Test-CommandExists code) { 'code' }
elseif (Test-CommandExists notepad++) { 'notepad++' }
elseif (Test-CommandExists sublime_text) { 'sublime_text' }
else { 'notepad' }
# Quick Access to Editing the Profile
function Edit-Profile {
edit $PROFILE.CurrentUserCurrentHost
}
function New-File($file) {
"" | Out-File $file -Encoding UTF8
}
function Get-RecursiveItems($name) {
Get-ChildItem -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Output "$($_.FullName)"
}
}
function Get-PubIP {
(Invoke-WebRequest http://ifconfig.me/ip).Content
}
function Update-Profile {
& $PROFILE
}
function Expand-Zip ($file) {
Write-Output("Extracting", $file, "to", $pwd)
$fullFile = Get-ChildItem -Path $pwd -Filter $file | ForEach-Object { $_.FullName }
Expand-Archive -Path $fullFile -DestinationPath $pwd
}
function Find-String($regex, $dir) {
if ( $dir ) {
Get-ChildItem $dir | Select-String $regex
return
}
$input | Select-String $regex
}
function Set-String($file, $find, $replace) {
(Get-Content $file).replace("$find", $replace) | Set-Content $file
}
function Get-InitialRows {
param($Path, $n = 10)
Get-Content $Path -Head $n
}
function Get-LastRows {
param($Path, $n = 10, [switch]$f = $false)
Get-Content $Path -Tail $n -Wait:$f
}
function Get-Paths {
$delim = ':'
if ( $IsWindows ) {
$delim = ';'
}
$env:PATH -split ($delim)
}
function New-Link ($target, $link) {
New-Item -Path $link -ItemType SymbolicLink -Value $target
}
Set-Alias -Name edit -Value $EDITOR
Set-Alias -Name ep -Value Edit-Profile
Set-Alias tig 'C:\Program Files\Git\usr\bin\tig.exe'
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'
# Enhanced PowerShell Experience
# Enhanced PSReadLine Configuration
$PSReadLineOptions = @{
EditMode = 'Emacs'
HistoryNoDuplicates = $true
HistorySearchCursorMovesToEnd = $true
PredictionSource = 'History'
PredictionViewStyle = 'ListView'
BellStyle = 'None'
Colors = @{
Command = '#87CEEB' # SkyBlue (pastel)
Parameter = '#98FB98' # PaleGreen (pastel)
Operator = '#FFB6C1' # LightPink (pastel)
Variable = '#DDA0DD' # Plum (pastel)
String = '#FFDAB9' # PeachPuff (pastel)
Number = '#B0E0E6' # PowderBlue (pastel)
Type = '#F0E68C' # Khaki (pastel)
Comment = '#D3D3D3' # LightGray (pastel)
Keyword = '#8367c7' # Violet (pastel)
Error = '#FF6347' # Tomato (keeping it close to red for visibility)
}
}
Set-PSReadLineOption @PSReadLineOptions
# Custom key handlers
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardDeleteWord
Set-PSReadLineKeyHandler -Chord 'Alt+d' -Function DeleteWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+LeftArrow' -Function BackwardWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+RightArrow' -Function ForwardWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+z' -Function Undo
Set-PSReadLineKeyHandler -Chord 'Ctrl+y' -Function Redo
# Custom functions for PSReadLine
Set-PSReadLineOption -AddToHistoryHandler {
param($line)
$sensitive = @('password', 'secret', 'token', 'apikey', 'connectionstring')
$hasSensitive = $sensitive | Where-Object { $line -match $_ }
return ($null -eq $hasSensitive)
}
# Improved prediction settings
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -MaximumHistoryCount 10000
# Custom completion for common commands
$scriptblock = {
param($wordToComplete, $commandAst, $cursorPosition)
$customCompletions = @{
'git' = @('status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout')
'mvn' = @('compile', 'package', 'test', 'install', 'verify', 'deploy')
}
$command = $commandAst.CommandElements[0].Value
if ($customCompletions.ContainsKey($command)) {
$customCompletions[$command] | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
Register-ArgumentCompleter -Native -CommandName git, mvn -ScriptBlock $scriptblock
$scriptblock = {
param($wordToComplete, $commandAst, $cursorPosition)
dotnet complete --position $cursorPosition $commandAst.ToString() |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock $scriptblock
# Setting Prompt with Oh My Posh
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\peru.omp.json" | Invoke-Expression
if (Get-Command zoxide -ErrorAction SilentlyContinue) {
Invoke-Expression (& { (zoxide init --cmd cd powershell | Out-String) })
}
else {
Write-Host "zoxide command not found. Attempting to install via winget..."
try {
winget install -e --id ajeetdsouza.zoxide
Write-Host "zoxide installed successfully. Initializing..."
Invoke-Expression (& { (zoxide init powershell | Out-String) })
}
catch {
Write-Error "Failed to install zoxide. Error: $_"
}
}
Set-Alias -Name z -Value __zoxide_z -Option AllScope -Scope Global -Force
Set-Alias -Name zi -Value __zoxide_zi -Option AllScope -Scope Global -Force
if (-not (Get-Module -ListAvailable -Name Microsoft.WinGet.CommandNotFound) -and $IsWindows) {
Install-Module -Name Microsoft.WinGet.CommandNotFound -Scope CurrentUser -Force -SkipPublisherCheck
}
if ($IsWindows) {
Import-Module -Name Microsoft.WinGet.CommandNotFound
}
function Add-Module ($moduleName) {
if (-not (Get-Module -ListAvailable -Name $moduleName)) {
Install-Module -Name $moduleName -Scope CurrentUser -Force -SkipPublisherCheck
}
}
# Import Modules and External Profiles
Add-Module Terminal-Icons
Import-Module -Name Terminal-Icons
Add-Module cd-extras
Import-Module -Name cd-extras
Add-Module PsHosts
Import-Module -Name PsHosts
Add-Module z
Import-Module -Name z
# PowerShell FZF integration
Add-Module PSFzf
Import-Module -Name PSFzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+f' -PsReadlineChordReverseHistory 'Ctrl+r'
Set-PsFzfOption -EnableAliasFuzzyKillProcess -EnableAliasFuzzyEdit -EnableAliasFuzzyGitStatus -EnableAliasFuzzySetLocation
# example command - use $Location with a different command:
$commandOverride = [ScriptBlock]{ param($Location) Write-Host $Location }
# pass your override to PSFzf:
Set-PsFzfOption -AltCCommand $commandOverride