Skip to content

Add support for left/right navigation of entire pipeline stages #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkeithhill opened this issue Sep 13, 2013 · 10 comments
Closed

Add support for left/right navigation of entire pipeline stages #22

rkeithhill opened this issue Sep 13, 2013 · 10 comments
Labels
Issue-Enhancement It's a feature request.

Comments

@rkeithhill
Copy link
Contributor

Say I have this command with the cursor the location highlighted:

C:> Get-Process | Where Handles -gt >><< 500 | Format-Table ProcessName,Handles

We have LeftArrow/RightArrow to move a char at a time and Ctrl+Left/RightArrow to jump a word at a time. Considering the fundamental pipeline stages nature of PowerShell, it would be handy to be able to jump backward and forward through the pipeline stages using say Ctrl+Shift+Left/RightArrow. Pressing Ctrl+Shift+LeftArrow in the above example should put the cursor here:

C:> Get-Process | >>W<<here Handles -gt 500 | Format-Table ProcessName,Handles

Pressing the same key binding again would put it here:

C:> >>G<<et-Process | Where Handles -gt 500 | Format-Table ProcessName,Handles

Then pressing Ctrl+Shift+RightArrow twice would put it here:

C:> Get-Process | Where Handles -gt 500 | >>F<<ormat-Table ProcessName,Handles

@lzybkr
Copy link
Contributor

lzybkr commented Sep 13, 2013

Emacs mode will have a binding to move to the next/previous character, e.g. Ctrl+],| would move to the next | and Alt+Ctrl+],| would move to the previous |.

With this capability, I'm not sure it's worth adding something special for pipes.

@rkeithhill
Copy link
Contributor Author

I think cmd users need bells and whistles like this but a more "Windows" friendly key-binding for this would be nice. Maybe Alt+Left/RightArrow,|

@lzybkr
Copy link
Contributor

lzybkr commented Dec 9, 2013

F3/Shift+F3 roughly match Visual Studio. Give it a try and see how it feels. 933cda8

@lzybkr lzybkr closed this as completed Dec 9, 2013
@rkeithhill
Copy link
Contributor Author

Cool. Thanks! BTW is there a way I can use Set-PSReadlineKeyhander and -Scriptblock to configure say a Ctrl+BackslashKey to do a F3 with arg '|' and Ctrl+Shift+BackslashKey to do a Shift+F3 with arg '|'? That would be more smooth to navigate quickly around a longer one-liner. Having to reach up to F3 and press another key combo (shift+\ for |) isn't as smooth (or quick). I know, first world problems. :-)

What I have isn't working:

Set-PSReadlineKeyHandler -Chord Ctrl+Oem102 `
                         -BriefDescription SearchPipeChar `
                         -LongDescription "Searches forward for the next pipeline character" `
                         -ScriptBlock {
   param($key, $arg)
   #Write-Host "SearchPipeChar: $key and $arg"
   [PSConsoleUtilities.PSConsoleReadLine]::CharacterSearch($key, '|')
}

I assume I need to use Oem102 (backslash key which is also home to the pipe character)?

What would be real slick is to have something like VS's inline find - Ctrl+F brings up a character mode (ala demo mode) to have use enter text, press F3 and Shift+F3 for forward/backward matches and then some key to dismiss the UI (esc?). :-)

Keith

Date: Mon, 9 Dec 2013 13:14:17 -0800
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [PSReadLine] Add support for left/right navigation of entire pipeline stages (#22)

F3/Shift+F3 roughly match Visual Studio. Give it a try and see how it feels. 933cda8


Reply to this email directly or view it on GitHub.

@rkeithhill
Copy link
Contributor Author

Hmm, thought this would get me closer but no:

Set-PSReadlineKeyHandler -Key Ctrl+P `
                         -BriefDescription SearchPipeChar `
                         -LongDescription "Searches forward for the next pipeline character" `
                         -ScriptBlock {
   param($key, $arg)

   [PSConsoleUtilities.PSConsoleReadLine]::CharacterSearch($key, $arg)
   [PSConsoleUtilities.PSConsoleReadLine]::Insert("|")
}

@lzybkr
Copy link
Contributor

lzybkr commented Dec 11, 2013

With a trivial change to CharacterSearch, your first example will work. Until I make that change, instead of using CharacterSearch, you can combine GetBufferState and SetCursorPosition with your own string searching. I'll leave that as an exercise for the reader - it should be pretty simple.

As for determining what key to use - I usually start with something like:
$k = [Console]::ReadKey($true)
then type the key I want to bind - that tells me which Oem* character I need. Note that I'm investigating improving the string->key conversion because it's really too hard right now, but I have to learn more about keyboard layouts and whatnot before we'll see any changes.

@rkeithhill
Copy link
Contributor Author

Thanks. WRT string->key conversion, it would be sweet to use Demo mode to determine what argument to provide to -Chord.

Date: Tue, 10 Dec 2013 21:08:49 -0800
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [PSReadLine] Add support for left/right navigation of entire pipeline stages (#22)

With a trivial change to CharacterSearch, your first example will work. Until I make that change, instead of using CharacterSearch, you can combine GetBufferState and SetCursorPosition with your own string searching. I'll leave that as an exercise for the reader - it should be pretty simple.

As for determining what key to use - I usually start with something like:

$k = [Console]::ReadKey($true)

then type the key I want to bind - that tells me which Oem* character I need. Note that I'm investigating improving the string->key conversion because it's really too hard right now, but I have to learn more about keyboard layouts and whatnot before we'll see any changes.


Reply to this email directly or view it on GitHub.

@rkeithhill
Copy link
Contributor Author

Got this to work:

Set-PSReadlineKeyHandler -Chord Ctrl+Oem5 `
                         -BriefDescription SearchPipeChar `
                         -LongDescription "Searches forward for the next pipeline character" `
                         -ScriptBlock {
    param($key, $arg)

    $line = $null
    $cursor = $null
    [PSConsoleUtilities.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor)

    if (($cursor + 1) -gt $line.Length) { return }
    $ndx = $line.IndexOf('|', $cursor+1)
    if ($ndx -ne -1) {
        [PSConsoleUtilities.PSConsoleReadline]::SetCursorPosition($ndx)
    }
}
Set-PSReadlineKeyHandler -Chord Ctrl+Shift+Oem5 `
                         -BriefDescription SearchPipeChar `
                         -LongDescription "Searches forward for the next pipeline character" `
                         -ScriptBlock {
    param($key, $arg)

    $line = $null
    $cursor = $null
    [PSConsoleUtilities.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor)

    if (($cursor - 1) -lt 0) { return }
    $ndx = $line.LastIndexOf('|', $cursor-1)
    if ($ndx -ne -1) {
        [PSConsoleUtilities.PSConsoleReadline]::SetCursorPosition($ndx)
    }
}

@lzybkr
Copy link
Contributor

lzybkr commented Dec 14, 2013

Now that I convinced you to write it yourself, I added support to CharacterSearch so you original example will work. c0059eb

@rkeithhill
Copy link
Contributor Author

Cool. I look forward to the next "latest" release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants