Skip to content

Commit

Permalink
Comment out completions
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyTake-Off committed Sep 20, 2024
1 parent 482625c commit 669b0a8
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions winfiles/.dots/scripts/completions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GitHub Repo - https://github.com/RustyTake-Off/dotfiles
.NOTES
Author - RustyTake-Off
Version - 0.1.7
Version - 0.1.8
#>

[CmdletBinding(SupportsShouldProcess)]
Expand Down Expand Up @@ -47,50 +47,49 @@ process {
}

# Completion for git
if (Get-Module -Name posh-git) {
$GitPromptSettings.EnablePromptStatus = $false
$GitPromptSettings.EnableFileStatus = $false
} else {
if (-not (Get-Module -Name posh-git)) {
Import-Module -Name posh-git
}

if ($GitPromptSettings) {
$GitPromptSettings.EnablePromptStatus = $false
$GitPromptSettings.EnableFileStatus = $false
}

# Completion for winget - https://learn.microsoft.com/en-us/windows/package-manager/winget/tab-completion#enable-tab-completion
if (Get-Command -Name winget) {
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
# if (Get-Command -Name winget) {
# Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
# param($wordToComplete, $commandAst, $cursorPosition)
# [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
# $Local:word = $wordToComplete.Replace('"', '""')
# $Local:ast = $commandAst.ToString().Replace('"', '""')
# winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
# [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
# }
# }
# }

# Completion for azure-cli - https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=winget#enable-tab-completion-in-powershell
if (Get-Command -Name az) {
Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$completion_file = New-TemporaryFile
$env:ARGCOMPLETE_USE_TEMPFILES = 1
$env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file
$env:COMP_LINE = $wordToComplete
$env:COMP_POINT = $cursorPosition
$env:_ARGCOMPLETE = 1
$env:_ARGCOMPLETE_SUPPRESS_SPACE = 0
$env:_ARGCOMPLETE_IFS = "`n"
$env:_ARGCOMPLETE_SHELL = 'powershell'
az 2>&1 | Out-Null
Get-Content $completion_file | Sort-Object | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL
}
}
# if (Get-Command -Name az) {
# Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
# param($commandName, $wordToComplete, $cursorPosition)
# $completion_file = New-TemporaryFile
# $env:ARGCOMPLETE_USE_TEMPFILES = 1
# $env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file
# $env:COMP_LINE = $wordToComplete
# $env:COMP_POINT = $cursorPosition
# $env:_ARGCOMPLETE = 1
# $env:_ARGCOMPLETE_SUPPRESS_SPACE = 0
# $env:_ARGCOMPLETE_IFS = "`n"
# $env:_ARGCOMPLETE_SHELL = 'powershell'
# az 2>&1 | Out-Null
# Get-Content $completion_file | Sort-Object | ForEach-Object {
# [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
# }
# Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL
# }
# }
} catch {
Write-Error "Error in line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)"
exit 1
throw "Error in line $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.Message)"
}
}

0 comments on commit 669b0a8

Please sign in to comment.