a collection of my configuration files
at main 132 lines 5.1 kB view raw
1# my functions 2function search { 3 Write-Host -ForegroundColor 11 "search $($args[0]) in Chocolatey" && 4 choco search $($args[0]) && 5 Write-Host -ForegroundColor 11 "`nsearch $($args[0]) in Scoop" && 6 scoop search $($args[0]) && 7 Write-Host -ForegroundColor 11 "`n`nsearch $($args[0]) in Winget" && 8 winget search $($args[0]) ` 9} 10 11function upgrade { 12 sudo choco upgrade all -y && 13 scoop update && 14 winget upgrade --all 15} 16 17function disks { GET-WMIOBJECT -query "SELECT * from Win32_DiskDrive" } 18 19# my aliases 20remove-alias r 21 22# VIM mode 23Set-PSReadLineOption -EditMode vi -viModeIndicator Cursor 24 25function OnViModeChange { 26 if ($args[0] -eq 'Command') { 27 # Set the cursor to a blinking block. 28 Write-Host -NoNewLine "`e[1 q" 29 } else { 30 # Set the cursor to a blinking line. 31 Write-Host -NoNewLine "`e[5 q" 32 } 33} 34Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange 35 36# starship prompt 37$ENV:STARSHIP_CONFIG = "$HOME\.config\starship.toml" 38$ENV:STARSHIP_CACHE = "$HOME\AppData\Local\Temp" 39Invoke-Expression (&starship init powershell) 40 41# FZF 42Enable-PsFzfAliases 43Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r' 44# replace tab expansion with fzf 45Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion } 46 47 48# GITHUB COPILOT CLI - https://github.blog/changelog/2024-03-21-github-copilot-general-availability-in-the-cli/ 49 50function ghcs { 51 # Debug support provided by common PowerShell function parameters, which is natively aliased as -d or -db 52 # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.4#-debug 53 param( 54 [ValidateSet('gh', 'git', 'shell')] 55 [Alias('t')] 56 [String]$Target = 'shell', 57 58 [Parameter(Position=0, ValueFromRemainingArguments)] 59 [string]$Prompt 60 ) 61 begin { 62 # Create temporary file to store potential command user wants to execute when exiting 63 $executeCommandFile = New-TemporaryFile 64 65 # Store original value of GH_DEBUG environment variable 66 $envGhDebug = $Env:GH_DEBUG 67 } 68 process { 69 if ($PSBoundParameters['Debug']) { 70 $Env:GH_DEBUG = 'api' 71 } 72 73 gh copilot.exe suggest -t $Target -s "$executeCommandFile" $Prompt 74 } 75 end { 76 # Execute command contained within temporary file if it is not empty 77 if ($executeCommandFile.Length -gt 0) { 78 # Extract command to execute from temporary file 79 $executeCommand = (Get-Content -Path $executeCommandFile -Raw).Trim() 80 81 # Insert command into PowerShell up/down arrow key history 82 [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executeCommand) 83 84 # Insert command into PowerShell history 85 $now = Get-Date 86 $executeCommandHistoryItem = [PSCustomObject]@{ 87 CommandLine = $executeCommand 88 ExecutionStatus = [Management.Automation.Runspaces.PipelineState]::NotStarted 89 StartExecutionTime = $now 90 EndExecutionTime = $now.AddSeconds(1) 91 } 92 Add-History -InputObject $executeCommandHistoryItem 93 94 # Execute command 95 Write-Host "`n" 96 Invoke-Expression $executeCommand 97 } 98 } 99 clean { 100 # Clean up temporary file used to store potential command user wants to execute when exiting 101 Remove-Item -Path $executeCommandFile 102 103 # Restore GH_DEBUG environment variable to its original value 104 $Env:GH_DEBUG = $envGhDebug 105 } 106} 107 108function ghce { 109 # Debug support provided by common PowerShell function parameters, which is natively aliased as -d or -db 110 # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.4#-debug 111 param( 112 [Parameter(Position=0, ValueFromRemainingArguments)] 113 [string[]]$Prompt 114 ) 115 begin { 116 # Store original value of GH_DEBUG environment variable 117 $envGhDebug = $Env:GH_DEBUG 118 } 119 process { 120 if ($PSBoundParameters['Debug']) { 121 $Env:GH_DEBUG = 'api' 122 } 123 124 gh copilot.exe explain $Prompt 125 } 126 clean { 127 # Restore GH_DEBUG environment variable to its original value 128 $Env:GH_DEBUG = $envGhDebug 129 } 130} 131 132fnm env --use-on-cd | Out-String | Invoke-Expression