Created
June 9, 2025 17:37
-
-
Save P9iman/c77afe2e158a767a8cc5b1c22b0e28cc to your computer and use it in GitHub Desktop.
Powershell7 Profile Script mit custom commands und Module imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# oh-my-posh init pwsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/refs/heads/main/themes/stelbent.minimal.omp.json' | Invoke-Expression | |
oh-my-posh init pwsh --config 'C:/Users/Paiman/Documents/omp_themes/mytheme.omp.json' | Invoke-Expression | |
function touch { | |
param( | |
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)] | |
[String[]]$FileList | |
) | |
# Dateinamen verarbeiten, indem Kommata entfernt werden | |
$FilePaths = $FileList -join "," -split "," | |
foreach ($FilePath in $FilePaths) { | |
if (Test-Path -Path $FilePath) { | |
(Get-Item $FilePath).LastWriteTime = Get-Date | |
} else { | |
New-Item -Path $FilePath -ItemType File -Force | Out-Null | |
} | |
} | |
} | |
function Open-Explorer { | |
Invoke-Item -Path (Get-Location) | |
} | |
function Open-NotepadPlusPlus { | |
param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[String]$FilePath | |
) | |
& "C:\Program Files\Notepad++\notepad++.exe" $FilePath | |
} | |
# Funktion: Verschiebt Dateien in den Papierkorb | |
function Remove-ToRecycleBin { | |
param ( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[string[]]$Path | |
) | |
foreach ($item in $Path) { | |
# Pfad in absoluten Pfad umwandeln | |
$absolutePath = Resolve-Path -Path $item -ErrorAction SilentlyContinue | |
if (-not $absolutePath) { | |
Write-Error "Der Pfad '$item' existiert nicht." | |
continue | |
} | |
Add-Type -AssemblyName Microsoft.VisualBasic | |
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($absolutePath.Path, 'OnlyErrorDialogs', 'SendToRecycleBin') | |
Write-Host "Die Datei '$item' wurde in den Papierkorb verschoben." -ForegroundColor Green | |
} | |
} | |
function Open-PDF { | |
param( | |
[string]$FilePath | |
) | |
if (-Not (Test-Path $FilePath)) { | |
Write-Error "Die Datei '$FilePath' wurde nicht gefunden." | |
return | |
} | |
# Pfad zu Okular | |
$okularPath = "C:\Users\Paiman\AppData\Local\Okular\bin\okular.exe" | |
if (-Not (Test-Path $okularPath)) { | |
Write-Error "Okular wurde nicht gefunden. Bitte überprüfe den Installationspfad." | |
return | |
} | |
Start-Process $okularPath -ArgumentList $FilePath | |
} | |
function Show-Ip { | |
param ( | |
[string]$InterfaceName = "all", | |
[ValidateSet("4", "6")] | |
[string]$v = "4" # Standardmäßig IPv4 | |
) | |
$AddressFamily = if ($v -eq "4") { "IPv4" } else { "IPv6" } | |
if ($InterfaceName -eq "all") { | |
Get-NetAdapter | ForEach-Object { | |
$adapter = $_ | |
if ($adapter.Status -ne "Up") { | |
Write-Host "Skipping adapter: $($adapter.Name) (Status: $($adapter.Status))" -ForegroundColor Yellow | |
return | |
} | |
$ipAddresses = Get-NetIPAddress -AddressFamily $AddressFamily -InterfaceAlias $adapter.Name -ErrorAction SilentlyContinue | |
if ($ipAddresses) { | |
$ipAddresses | ForEach-Object { | |
[PSCustomObject]@{ | |
InterfaceAlias = $_.InterfaceAlias | |
IPAddress = $_.IPAddress | |
NetworkCardModel = $adapter.InterfaceDescription | |
} | |
} | |
} else { | |
Write-Host "No IP address found for adapter: $($adapter.Name)" -ForegroundColor Yellow | |
} | |
} | |
} else { | |
$adapter = Get-NetAdapter -Name $InterfaceName | |
$ipAddresses = Get-NetIPAddress -AddressFamily $AddressFamily -InterfaceAlias $adapter.Name -ErrorAction SilentlyContinue | |
if ($ipAddresses) { | |
$ipAddresses | ForEach-Object { | |
[PSCustomObject]@{ | |
InterfaceAlias = $_.InterfaceAlias | |
IPAddress = $_.IPAddress | |
NetworkCardModel = $adapter.InterfaceDescription | |
} | |
} | |
} else { | |
Write-Host "No IP address found for adapter: $InterfaceName" -ForegroundColor Yellow | |
} | |
} | |
} | |
Set-Alias -Name ls -Value PowerColorLS -Option AllScope | |
Set-Alias ip Show-Ip | |
Set-Alias -Name pdf -Value Open-PDF | |
# Alias: 'rm' verwendet jetzt Remove-ToRecycleBin | |
Set-Alias -Name rm -Value Remove-ToRecycleBin | |
Set-Alias npp Open-NotepadPlusPlus | |
Set-Alias explorer Open-Explorer | |
Set-Alias -Name ff -Value fastfetch | |
#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module | |
Import-Module -Name Microsoft.WinGet.CommandNotFound | |
#f45873b3-b655-43a6-b217-97c00aa0db58 | |
Import-Module -Name Terminal-Icons | |
Import-Module -Name PowerColorLS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment