Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9764

Insert text in Powershell prompt using control sequence ("chord")

$
0
0

I have a fzf script that lists all branches that satisfy some requirement. It looks like this:

function gbr{    $b = git branch -a    $sel = echo $b | ... some processing ... | fzf    echo $sel}

What I want is, in Powershell prompt, is to send a control sequence ("Chord"), i.e. Ctrl+u, which will call the script and insert the script's result directly in the prompt at the cursor location.

This would work exactly the same as following code:

Import-Module PSFzfSet-PsFzfOption -PSReadlineChordProvider 'Ctrl+t'

i.e: When I click Ctrl+t during prompt, I can choose some file interactively with fzf which will be inserted in prompt.

My current attempt (I found this code on the internet and it doesn't work):

Set-PSReadLineKeyHandler -Chord Ctrl+U -ScriptBlock {    [Microsoft.PowerShell.PSConsoleReadLine]::Insert('abc')}

This is the simplest version of what I want to do: send Ctrl+u sequence to make 'abc' appear in prompt.

Bonus: allow multiple selection which will list multiple branches in fzf. Ctrl+t command I provided earlier has this functionality.

Thanks in advance.


Viewing all articles
Browse latest Browse all 9764

Trending Articles