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:
Chapman Pendery
2023-10-07 20:28:52 -07:00
parent 73ca51f457
commit f339697532
9 changed files with 68 additions and 55 deletions
-9
View File
@@ -1,11 +1,2 @@
node_modules/
.fig/
*.log
__debug_*.exe
debug.test*.exe
clac
.env*
dist/
t*.md
__pycache__
build/
+3
View File
@@ -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
View File
@@ -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"
}
}
}
+26
View File
@@ -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()
}
+26
View File
@@ -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()
}
+2 -3
View File
@@ -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__'
-40
View File
@@ -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"
}
}
-1
View File
@@ -32,5 +32,4 @@ export const action = async (options: RootCommandOptions) => {
} else {
process.exit(0);
}
// TODO: cache executed command to add to history
};
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env node
import { Command } from "commander";
import bind from "./commands/bind.js";