Skip to content

Conversation

@jakenuts
Copy link

As an opener, never written GO in my life (lots of others tho) so please feel more than free to say "nope" either because the feature is unncessary, or poorly implemented.

I wanted to be able to submit a query to shell-ai and have the response copied to the clipboard and return without further intervention. To do this I added a 'SHELLAI_MODE' environment variable which when set to 'silent' will follow the same path as the user hitting enter. As copying & quitting were now associated with the keypress or the silent mode, I moved that bit of logic to a copyAndQuit func.

Again, maybe entirely useless. With this script tho it's now my goto.


# qa.ps1

# Capture arguments and append OS/shell specifics
$arguments = ($args -join ' ') + " (Windows 11 / PowerShell 7)"

# Set the mode to 'silent'
$env:SHELLAI_MODE="silent"

# Execute q.exe as a hidden window and wait for it to finish
Start-Process -FilePath "C:\Program Files\shell-ai\q.exe" -WindowStyle hidden -ArgumentList $arguments -Wait

# Retrieve the clipboard contents
$clipboardContent = Get-Clipboard

# Step 4: Present the result
Write-Host ""
Write-Host "🤖 ⟬ $clipboardContent ⟭"
Write-Host "🪄 Press Enter to Execute"

# Read key if enter continue otherwise quit
$keyInfo = [System.Console]::ReadKey($true)
if ($keyInfo.Key -ne 'Enter') {
    exit
}

# Step 4: Execute the clipboard contents as a command in the current shell
Invoke-Expression $clipboardContent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant