(buf io.StringWriter, name string, includeDesc bool)
| 26 | ) |
| 27 | |
| 28 | func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) { |
| 29 | // Variables should not contain a '-' or ':' character |
| 30 | nameForVar := name |
| 31 | nameForVar = strings.ReplaceAll(nameForVar, "-", "_") |
| 32 | nameForVar = strings.ReplaceAll(nameForVar, ":", "_") |
| 33 | |
| 34 | compCmd := ShellCompRequestCmd |
| 35 | if !includeDesc { |
| 36 | compCmd = ShellCompNoDescRequestCmd |
| 37 | } |
| 38 | WriteStringAndCheck(buf, fmt.Sprintf(`# powershell completion for %-36[1]s -*- shell-script -*- |
| 39 | |
| 40 | function __%[1]s_debug { |
| 41 | if ($env:BASH_COMP_DEBUG_FILE) { |
| 42 | "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE" |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | filter __%[1]s_escapeStringWithSpecialChars { |
| 47 | `+" $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|\"|`|\\||<|>|&','`$&'"+` |
| 48 | } |
| 49 | |
| 50 | [scriptblock]${__%[2]sCompleterBlock} = { |
| 51 | param( |
| 52 | $WordToComplete, |
| 53 | $CommandAst, |
| 54 | $CursorPosition |
| 55 | ) |
| 56 | |
| 57 | # Get the current command line and convert into a string |
| 58 | $Command = $CommandAst.CommandElements |
| 59 | $Command = "$Command" |
| 60 | |
| 61 | __%[1]s_debug "" |
| 62 | __%[1]s_debug "========= starting completion logic ==========" |
| 63 | __%[1]s_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition" |
| 64 | |
| 65 | # The user could have moved the cursor backwards on the command-line. |
| 66 | # We need to trigger completion from the $CursorPosition location, so we need |
| 67 | # to truncate the command-line ($Command) up to the $CursorPosition location. |
| 68 | # Make sure the $Command is longer then the $CursorPosition before we truncate. |
| 69 | # This happens because the $Command does not include the last space. |
| 70 | if ($Command.Length -gt $CursorPosition) { |
| 71 | $Command=$Command.Substring(0,$CursorPosition) |
| 72 | } |
| 73 | __%[1]s_debug "Truncated command: $Command" |
| 74 | |
| 75 | $ShellCompDirectiveError=%[4]d |
| 76 | $ShellCompDirectiveNoSpace=%[5]d |
| 77 | $ShellCompDirectiveNoFileComp=%[6]d |
| 78 | $ShellCompDirectiveFilterFileExt=%[7]d |
| 79 | $ShellCompDirectiveFilterDirs=%[8]d |
| 80 | $ShellCompDirectiveKeepOrder=%[9]d |
| 81 | |
| 82 | # Prepare the command to request completions for the program. |
| 83 | # Split the command at the first space to separate the program and arguments. |
| 84 | $Program,$Arguments = $Command.Split(" ",2) |
| 85 |
no test coverage detected