-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathpowershell_plugin.ps1
More file actions
53 lines (41 loc) · 1.51 KB
/
powershell_plugin.ps1
File metadata and controls
53 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
### Codex CLI setup - start
$nl_cli_script = "{{codex_query_path}}"
# this function takes the input from the buffer and passes it to codex_query.py
function create_completion() {
param (
[Parameter (Mandatory = $true)] [string] $buffer
)
if ($nl_cli_script -eq "" -or !(Test-Path($nl_cli_script))) {
Write-Output "# Please update the nl_cli_script path in the profile!"
return "`nnotepad $profile"
}
$output = echo -n $buffer | python $nl_cli_script
return $output
}
Set-PSReadLineKeyHandler -Key Ctrl+g `
-BriefDescription NLCLI `
-LongDescription "Calls Codex CLI tool on the current buffer" `
-ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
# get response from create_completion function
$output = create_completion($line)
# get first char of the response
# if its not #, add # to the beginning of the response
if ($output[0] -ne "#") {
$output = "# $output"
}
# note: add multiline fix
# check if output is not null
if ($output -ne $null) {
foreach ($str in $output) {
if ($str -ne $null -and $str -ne "") {
[Microsoft.PowerShell.PSConsoleReadLine]::AddLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($str)
}
}
}
}
### Codex CLI setup - end