Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powershell: escape variable with curly brackets #1960

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions powershell_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ filter __%[1]s_escapeStringWithSpecialChars {
`+" $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|\"|`|\\||<|>|&','`$&'"+`
}

[scriptblock]$__%[2]sCompleterBlock = {
[scriptblock]${__%[2]sCompleterBlock} = {
param(
$WordToComplete,
$CommandAst,
Expand Down Expand Up @@ -122,7 +122,7 @@ filter __%[1]s_escapeStringWithSpecialChars {

__%[1]s_debug "Calling $RequestComp"
# First disable ActiveHelp which is not supported for Powershell
$env:%[10]s=0
${env:%[10]s}=0

#call the command store the output in $out and redirect stderr and stdout to null
# $Out is an array contains each line per element
Expand Down Expand Up @@ -279,7 +279,7 @@ filter __%[1]s_escapeStringWithSpecialChars {
}
}

Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock $__%[2]sCompleterBlock
Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock ${__%[2]sCompleterBlock}
`, name, nameForVar, compCmd,
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpEnvVar(name)))
Expand Down
2 changes: 1 addition & 1 deletion powershell_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func TestPwshCompletionNoActiveHelp(t *testing.T) {

// check that active help is being disabled
activeHelpVar := activeHelpEnvVar(c.Name())
check(t, output, fmt.Sprintf("%s=0", activeHelpVar))
check(t, output, fmt.Sprintf("${env:%s}=0", activeHelpVar))
}