mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
feat: make cli executable & update all keybinding sets to support new cli surface & inject accepted results into history
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -1,11 +1,2 @@
|
||||
node_modules/
|
||||
.fig/
|
||||
*.log
|
||||
__debug_*.exe
|
||||
debug.test*.exe
|
||||
clac
|
||||
.env*
|
||||
dist/
|
||||
t*.md
|
||||
__pycache__
|
||||
build/
|
||||
Generated
+3
@@ -16,6 +16,9 @@
|
||||
"react": "^18.2.0",
|
||||
"wrap-ansi": "^8.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"clac": "build/index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node18": "^18.2.2",
|
||||
"@types/ink": "^2.0.3",
|
||||
|
||||
+9
-2
@@ -2,8 +2,15 @@
|
||||
"name": "@microsoft/clac",
|
||||
"version": "0.0.0",
|
||||
"description": "IDE style command line auto complete",
|
||||
"main": "./build/index.js",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"clac": "./build/index.js"
|
||||
},
|
||||
"files": [
|
||||
"build/**",
|
||||
"*.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node ./build/index.js",
|
||||
@@ -39,4 +46,4 @@
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
|
||||
$command = $null
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
|
||||
|
||||
$oldPrompt = $function:prompt
|
||||
function prompt {"`r"}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||
$prompt = $oldPrompt
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
|
||||
|
||||
$clac = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\clac\build\index.js"
|
||||
if ($command) {
|
||||
Start-Process -NoNewWindow -Wait "node" "$clac -c $command -s powershell"
|
||||
} else {
|
||||
Start-Process -NoNewWindow -Wait "node" "$clac -s powershell"
|
||||
}
|
||||
|
||||
$executedCommand = node $clac --history
|
||||
if ($executedCommand) {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
|
||||
}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
|
||||
$command = $null
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
|
||||
|
||||
$oldPrompt = $function:prompt
|
||||
function prompt {"`r"}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||
$prompt = $oldPrompt
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
|
||||
|
||||
$clac = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\clac\build\index.js"
|
||||
if ($command) {
|
||||
Start-Process -NoNewWindow -Wait "node" "$clac -c $command -s pwsh"
|
||||
} else {
|
||||
Start-Process -NoNewWindow -Wait "node" "$clac -s pwsh"
|
||||
}
|
||||
|
||||
$executedCommand = node $clac --history
|
||||
if ($executedCommand) {
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
|
||||
}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
__clac__() {
|
||||
clac "$READLINE_LINE"
|
||||
output=$(clac -o)
|
||||
eval "$output"
|
||||
clac -c "$READLINE_LINE" -s bash
|
||||
history -s $(clac --history)
|
||||
}
|
||||
|
||||
bind -x '"\C-a": __clac__'
|
||||
@@ -1,40 +0,0 @@
|
||||
Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
|
||||
$command = $null
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
|
||||
|
||||
$oldPrompt = $function:prompt
|
||||
function prompt {" `n"}
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||
$prompt = $oldPrompt
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
|
||||
|
||||
if ($command) {
|
||||
Start-Process -NoNewWindow -Wait "clac" "$command"
|
||||
} else {
|
||||
Start-Process -NoNewWindow -Wait "clac"
|
||||
}
|
||||
|
||||
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$pinfo.FileName = "clac"
|
||||
$pinfo.RedirectStandardError = $true
|
||||
$pinfo.RedirectStandardOutput = $true
|
||||
$pinfo.UseShellExecute = $false
|
||||
$pinfo.Arguments = "-o"
|
||||
$p = New-Object System.Diagnostics.Process
|
||||
$p.StartInfo = $pinfo
|
||||
$p.Start() | Out-Null
|
||||
$p.WaitForExit()
|
||||
$stdout = $p.StandardOutput.ReadToEnd()
|
||||
|
||||
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
|
||||
|
||||
$cmd,$args = $stdout -split ' ',2
|
||||
if ($cmd.Trim() -and $args.Trim()) {
|
||||
Start-Process -NoNewWindow -Wait "$cmd" "$args"
|
||||
} elseif ($cmd.Trim()) {
|
||||
Start-Process -NoNewWindow -Wait "$cmd"
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,4 @@ export const action = async (options: RootCommandOptions) => {
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
// TODO: cache executed command to add to history
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { Command } from "commander";
|
||||
|
||||
import bind from "./commands/bind.js";
|
||||
|
||||
Reference in New Issue
Block a user