From 095f7237689cf6a29bc6a33dadb5b6232e69a3cf Mon Sep 17 00:00:00 2001 From: Taken Date: Fri, 18 Oct 2024 11:48:05 +0200 Subject: [PATCH] Updated config --- Microsoft.PowerShell_profile.ps1 | 145 ++++++++++++++++++++++--------- 1 file changed, 104 insertions(+), 41 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index 50e5920..5bec887 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -1,18 +1,24 @@ -if (Get-Module -ListAvailable -Name PSWindowsUpdate) { +if (Get-Module -ListAvailable -Name PSWindowsUpdate) +{ Import-Module -Name PSWindowsUpdate -} else { +} else +{ Write-Host "PSWindowsUpdate module not found" -ForegroundColor Red } -if (Get-Module -ListAvailable -Name gsudoModule) { +if (Get-Module -ListAvailable -Name gsudoModule) +{ Import-Module -Name gsudoModule -} else { +} else +{ Write-Host "gsudoModule module not found" -ForegroundColor Red } -if (Get-Module -ListAvailable -Name Terminal-Icons) { +if (Get-Module -ListAvailable -Name Terminal-Icons) +{ Import-Module -Name Terminal-Icons -} else { +} else +{ Write-Host "Terminal-Icons module not found" -ForegroundColor Red } @@ -21,37 +27,61 @@ Set-Alias -Name reboot -Value Restart-Computer Set-Alias -Name shutdown -Value Stop-Computer Set-Alias -Name st -Value streamlink Set-Alias -Name v -Value nvim +Set-Alias -Name cat -Value batcat -function randomscript { +function batcat($file) +{ + bat $file --style=plain +} + +function randomscript +{ $artDir = "$env:USERPROFILE\asciiart" - if (Test-Path $artDir -ErrorAction SilentlyContinue) { + if (Test-Path $artDir -ErrorAction SilentlyContinue) + { $art = Get-ChildItem -Path $artDir | Get-Random Get-Content -Path $art | Write-Host -ForegroundColor DarkMagenta } } -function hsconnect { +function Get-Weather($location) +{ + # Invoke-RestMethod wttr.in/$location"?2FQ" + Invoke-RestMethod (-join("wttr.in/", $location, "?2FQ")) +} + +Set-Alias -Name weather -Value Get-Weather + +function hsconnect +{ netsh wlan connect name="Arc V2" } -function wificonnect($profilename) { +function wificonnect($profilename) +{ netsh wlan connect name=$profilename } -function lsfunc($dir) { eza -la --group-directories-first --git --git-repos --icons $dir } +function lsfunc($dir) +{ eza -la --group-directories-first --git --git-repos --icons $dir +} Set-Alias -Name ls -Value lsfunc -function Invoke-WinutilExtrnal { +function Invoke-WinutilExtrnal +{ Start-Process pwsh.exe -Verb runas -ArgumentList "-c irm https://christitus.com/win | iex" } -function Invoke-Winutil { +function Invoke-Winutil +{ Invoke-RestMethod "https://christitus.com/win" | Invoke-Expression } Set-Alias -Name winutil -Value Invoke-Winutil Set-Alias -Name winutilup -Value Invoke-WinutilExtrnal -function emd { - if (Get-Process -Name "emacs" -ErrorAction SilentlyContinue) { +function emd +{ + if (Get-Process -Name "emacs" -ErrorAction SilentlyContinue) + { Write-Host "====================================" -ForegroundColor Red Write-Host "Emacs is already running" -ForegroundColor DarkMagenta Write-Host "====================================" -ForegroundColor Red @@ -60,14 +90,16 @@ function emd { emacs --daemon & } -function nvims($appname, $file) { +function nvims($appname, $file) +{ $env:NVIM_APPNAME = $appname - if ($file) { + if ($file) + { nvim $file - } - else { + } else + { nvim } @@ -75,16 +107,19 @@ function nvims($appname, $file) { } -function grep($pattern, $file) { +function grep($pattern, $file) +{ - if (-not (Test-Path $file)) { + if (-not (Test-Path $file)) + { Write-Host "====================================" -ForegroundColor Red Write-Host "Error: $file does not exist" -ForegroundColor DarkMagenta Write-Host "====================================" -ForegroundColor Red return } - if (Test-Path $file -PathType Container) { + if (Test-Path $file -PathType Container) + { Write-Host "====================================" -ForegroundColor Red Write-Host "Error: $file is a directory" -ForegroundColor DarkMagenta Write-Host "====================================" -ForegroundColor Red @@ -93,50 +128,62 @@ function grep($pattern, $file) { Get-Content $file | Select-String $pattern } -function unzip ($file) { +function unzip ($file) +{ Write-Output("Extracting", $file, "to", $pwd) $fullFile = Get-ChildItem -Path $pwd -Filter .\cove.zip | ForEach-Object { $_.FullName } Expand-Archive -Path $fullFile -DestinationPath $pwd } -function frm($path) { +function frm($path) +{ Remove-Item $path -Force } -function lnk($link, $target) { +function lnk($link, $target) +{ New-Item -Type SymbolicLink -Path $link -Target $target } -Function Get-PubIP { +Function Get-PubIP +{ (Invoke-WebRequest http://ifconfig.me/ip ).Content } -function uptime { +function uptime +{ Get-WmiObject win32_operatingsystem | Select-Object csname, @{LABEL='LastBootUpTime'; - EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} + EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)} + } } -function reload_profile { +function reload_profile +{ & $profile } -function touch($file) { +function touch($file) +{ "" | Out-File $file -Encoding ASCII } -function export($name, $value) { +function export($name, $value) +{ set-item -force -path "env:$name" -value $value; } -function killall($name) { +function killall($name) +{ Get-Process $name -ErrorAction SilentlyContinue | Stop-Process } -function pgrep($name) { +function pgrep($name) +{ Get-Process $name } -function find-file($name) { +function find-file($name) +{ Get-ChildItem -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object { $place_path = $_.directory Write-Output "${place_path}\${_}" @@ -144,13 +191,12 @@ function find-file($name) { } function admin - { +{ if ($args.Count -gt 0) { $argList = "& '" + $args + "'" Start-Process "C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.15.3465.0_x64__8wekyb3d8bbwe\wt.exe" -Verb runAs -ArgumentList $argList - } - else + } else { Start-Process "C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.15.3465.0_x64__8wekyb3d8bbwe\wt.exe" -Verb runAs } @@ -161,19 +207,36 @@ Import-Module -Name Microsoft.WinGet.CommandNotFound #f45873b3-b655-43a6-b217-97c00aa0db58 $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" -if (Test-Path($ChocolateyProfile)) { +if (Test-Path($ChocolateyProfile)) +{ Import-Module "$ChocolateyProfile" } -if (Get-Command -Name fnm -ErrorAction SilentlyContinue) { +$ENV:FZF_DEFAULT_OPTS=@" +--color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 +--color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc +--color=marker:#b4befe,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8 +--color=selected-bg:#45475a +--multi +"@ + +if (Get-Command -Name direnv -ErrorAction SilentlyContinue) +{ + Invoke-Expression "$(direnv hook pwsh)" +} + +if (Get-Command -Name fnm -ErrorAction SilentlyContinue) +{ Invoke-Expression (& { (fnm env --shell power-shell --use-on-cd | Out-String) }) } -if (Get-Command -Name zoxide -ErrorAction SilentlyContinue) { +if (Get-Command -Name zoxide -ErrorAction SilentlyContinue) +{ Invoke-Expression (& { (zoxide init --cmd j powershell | Out-String) }) } -if (Get-Command -Name starship -ErrorAction SilentlyContinue) { +if (Get-Command -Name starship -ErrorAction SilentlyContinue) +{ Invoke-Expression (&starship init powershell) } randomscript