Skip to content

Home, End, Ctr+Arrow don't work (Arch/Linux 4.20) #8869

Closed

Description

@GlitterHorn

Steps to reproduce

  1. type something at the command prompt.
  2. Try to use Home or End to navigate the text.
  3. Try to use Ctrl+Arrow to navigate the text.
  4. Repeat 1-3 with text editor, e.g. nano.
  5. Observe.

Expected behavior

Home, End, and Ctrl+Arrow should behave as in bash - go to beginning of text, end of text, and skip words left and right.

Actual behavior

  • Home prints ~
  • End prints ~
  • Ctrl+Arrow does nothing

Environment data

I used yaourt on Arch to install.

Name                           Value
----                           -----
PSVersion                      6.2.0-preview.2
PSEdition                      Core
GitCommitId                    6.2.0-preview.2
OS                             Linux 4.20.0-arch1-1-ARCH #1 SMP PREEMPT Mon Dec 24 03:00:40 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Feb 12, 2019
  2. changed the title [-]My bug report[/-] [+]Home, End, Ctr+Arrow don't work (Arch/Linux 4.20)[/+] on Feb 12, 2019
  3. lzybkr commented on Feb 13, 2019

    @lzybkr
    Contributor

    This is most likely not a PowerShell problem.

    Try [Console]::ReadKey() then type Home. Output should look like:

    KeyChar  Key Modifiers
    -------  --- ---------
            Home         0
    

    I'm guessing it won't, in which case the problem could be with:

    • The setting for $env:TERM
    • .Net Core
    • The terminfo database
  4. rkeithhill commented on Sep 2, 2019

    @rkeithhill
    Collaborator

    Jason Shirk (@lzybkr) This is what I see on Ubuntu 18.04 (when I ssh in from Windows PS 7 and then start pwsh):

    09-01 21:23:44 3> [Console]::ReadKey()
    
    KeyChar    Key Modifiers
    -------    --- ---------
           Escape         0
    

    This is a real bummer as it makes moving around a command line painful. Here's the term info:

    09-01 21:29:01 4> dir env:term*
    
    Name                           Value
    ----                           -----
    TERM                           xterm-256color
    
  5. rkeithhill commented on Sep 9, 2019

    @rkeithhill
    Collaborator

    I'm pretty sure this is a PowerShell problem and probably not a PSReadLine problem. FWIW, I only see this when I SSH into our RedHat or Ubuntu build machines. I don't see this issue in Bash but I do see it when I then start up pwsh. I also see it when I start pwsh with pwsh -noprofile -noni which, I think, doesn't load PSReadLine. I see this when using both conhost and WindowsTerminal. And it is somewhat maddening TBH.

    PwshHomeEndBug

    This shows the issue on 6.2.2 but I just tried PS7-preview.3 and it behaves the exact same way.

  6. npodbielski commented on Sep 14, 2019

    @npodbielski

    Is there any chance to fix this. I would even try to do it myself since bash is maddeningly hard to do even easiest thing but I cannot swap pwsh because it lacks that little things like arrow keys support :)

  7. iSazonov commented on Sep 29, 2019

    @iSazonov
    Collaborator

    /cc Dongbo Wang (@daxian-dbw) Steve Lee (@SteveL-MSFT) If the problem is in .Net Core we need to get a fix before .Net Core 3.1 LTS.

    Keith Hill (@rkeithhill) Could you please make the test with simple C# app which only output Console.ReadKey()?

  8. SteveL-MSFT commented on Oct 3, 2019

    @SteveL-MSFT
    Member

    This seems most likely an issue in .NET Core. Agree with Ilya (@iSazonov) that a simple C# console app to repro would be ideal.

  9. AndrewSav commented on Oct 3, 2019

    @AndrewSav

    I'm slightly preplexed by these comments. This is an issue that is stabely reproducible in powershell and it does not seem to be and obvious way to reporoduce it in a C# console app. Also it does not seem that there is any evidence is given that it is not a Powershell issue.

    Could guys please clarify your line of thinking?

  10. SteveL-MSFT commented on Oct 3, 2019

    @SteveL-MSFT
    Member

    Andrew Savinykh (@AndrewSav) when PSReadLine is not involved as shown in Keith Hill (@rkeithhill)'s example, pwsh has a simple ReadLine that doesn't do any translation of keys. It is whatever the .NET API returns.

  11. AndrewSav commented on Oct 3, 2019

    @AndrewSav

    Steve Lee (@SteveL-MSFT) thank you for this. Will I be too far off if I conjecture, that these services (Home, End, Ctr+Arrow ) are not provided by ReadLine itself, but by something else, for example on windows by console host?

  12. AndrewSav commented on Oct 4, 2019

    @AndrewSav

    I tested the issue with pwsh 6.2.3 on Windows and Ubuntu Linux 18.04. I also tested it with a simple ReadLine console program. Here are the results.

    pwsh 6.2.3

    Home/End Ctrl-Arrows
    Windows 10 Works Works
    Ssh Does not work Does not work
    gnome-terminal Works Does not work
    xfce4-terminal Works Does not work

    .net core 3.0.100 program with Console.ReadLine

    Home/End Ctrl-Arrows
    Windows 10 Works Works
    Ssh Does not work Does not work
    gnome-terminal Does not work Does not work
    xfce4-terminal Does not work Does not work

    Console program text

    using System;
    
    namespace readline
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                Console.WriteLine("Hello World!");
                string hello = Console.ReadLine();
                Console.WriteLine(hello);
            }
        }
    }

    In bash it works in any combination.

  13. iSazonov commented on Oct 4, 2019

    @iSazonov
    Collaborator

    PowerShell uses ReadConsole P/Invoke on Windows that is power method.
    On Unix it emulates a line editor.
    Possible fix for local host could be in

    private string ReadLineFromConsole(bool endOnTab, string initialContent, bool calledFromPipeline, ref string restOfLine, ref ReadLineResult result)

    Perhaps Paul Higinbotham (@PaulHigin) could add more about ssh scenario.

    I already opened API request in CoreFX repo https://github.com/dotnet/corefx/issues/36175 long ago.

  14. 49 remaining items

  15. steven-willard commented on Jun 23, 2021

    @steven-willard

    This seems to be an issue still, I am unable to get ctrl+rightArrow or ctrl+LeftArrow to work in tokenizing the advance of the cursor location.

    Here is a quick pwsh function you can dump in your console to confirm the readkey value.

    function Test-KeyInputOnLinux {
      $key = ""
      while ($key.Key -ne "Enter") {
        $key = [System.Console]::ReadKey()
        $key
      }
    }
    

    LeftArrow and RightArrow returned just fine. (Along with the Control Modifier)

    Here is my version info, are we sure this is closed, or did I miss something?

    Name Value


    PSVersion 7.1.3
    PSEdition Core
    GitCommitId 7.1.3
    OS Linux 4.4.0-19041-Microsoft #488-Microsoft Mon Sep 01 13:43:00 PST 20…
    Platform Unix
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion 2.3
    SerializationVersion 1.1.0.1
    WSManStackVersion 3.0

  16. AndrewSav commented on Jun 25, 2021

    @AndrewSav

    Steven Willard II (@steven-willard) yep, it's still broken. If you read the issue history, it seems pretty impossible to get stuff fixed here, and this is not just this issue, it's general attitude towards the community, e.g read this or this. I personally abandoned any hope of this being fixed and moved on.

  17. npodbielski commented on Jun 25, 2021

    @npodbielski

    Andrew Savinykh (@AndrewSav) Steven Willard II (@steven-willard)
    Yep. I've been watching this thread for 2 years, lately mainly for fun and kicks. There should be banner:

    abandon hope all ye who enter here

    PS on Linux is just broken and looks line maintainers want it to work this way. It would be nice to have the same CLI for both OSes but it looks line it won't be PS.
    I think it would be easier to use bash via CygWin or something similar than PS on Linux.
    They should be just honest and kill it instead of lie to people that is 'cross-platform'.

  18. pencoe commented on Jun 25, 2021

    @pencoe

    Andrew Savinykh (@AndrewSav) Steven Willard II (@steven-willard) npodbielski

    Yep. I've been watching this thread for 2 years, lately mainly for fun and kicks. There should be banner:

    abandon hope all ye who enter here

    Yes, it's a pity... In this case (as far as i can tell) Powershell team and .NET team are playing "pass the buck" on each other.

    PS on Linux is just broken and looks line maintainers want it to work this way. It would be nice to have the same CLI for both OSes but it looks line it won't be PS.

    Which is very sad, because PS is more powerful than bash in many ways.

    I think it would be easier to use bash via CygWin or something similar than PS on Linux.

    No need to use CygWin since WSL and WSL2. In fact i found myself using bash on Windows more and more, because using PS on Linux isn't that easy as promised...

    Peter

  19. yodasad commented on Jan 24, 2022

    @yodasad

    There are too many comments in this thread... I cannot figure it out, why was the issue closed?
    Home, Ctrl + Arrow are still not working in pwsh on linux.

  20. yodasad commented on Jan 24, 2022

    @yodasad

    I've found a workaround: for Home and End you can use Ctrl+A and Ctrl+E respectively.

  21. artisticcheese commented on Jan 24, 2022

    @artisticcheese

    https://twitter.com/artisticcheese/status/1485698470791028741 leave comments under tweet to tell Microsoft that we still care.

    Twitter
    “@PowerShell_Team How come issue with broken Home, End keys not working on Linux is closed? (https://t.co/suSQ9qGTDw). Issue is still there and seems to be lying with Microsoft to fix and result of finger-pointing within MS who will do it”
  22. hepptho commented on Feb 4, 2022

    @hepptho

    On Ubuntu, with PowerShell 7.2, I got the expected behavior by adding the following to my profile.ps1:

    Set-PSReadLineKeyHandler -Chord Ctrl+LeftArrow -Function BackwardWord
    
    Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord
    
    Set-PSReadLineKeyHandler -Chord Home -Function BeginningOfLine
    
    Set-PSReadLineKeyHandler -Chord End -Function EndOfLine

    This requires the PSReadLine module to be installed, but I think it always should be by default. You can use Get-Module to check if you are unsure.

    To find the profile.ps1 file, you can use the $PROFILE variable or check the docs here.

    See also the docs on Set-PSReadLineKeyHandler and PSConsoleReadLine. The customization options seem extensive; it's pretty neat.

    That PSReadLine doesn't offer this behavior by default appears to be intentional, see PowerShell/PSReadLine#668.
    Instead (as yodasad noted) there are Ctrl+a and Ctrl+e for beginning / end of line, as well as alt-b and alt-f for backward word / forward word. Those are Emacs conventions, apparently, but that's where I'm out of my depth.

  23. artisticcheese commented on Feb 4, 2022

    @artisticcheese
    Set-PSReadLineKeyHandler -Chord End -Function EndOfLine

    This did not work for me from command line, I'm on 7.2.1 and Ubuntu 20.04.3 LTS (Focal Fossa) and I just executed those from command line instead of $PROFILE to test

    PS /home/cloudadmin> import-module PSReadLine
    PS /home/cloudadmin> Set-PSReadLineKeyHandler -Chord Home -Function BeginningOfLine
    PS /home/cloudadmin> Set-PSReadLineKeyHandler -Chord End -Function EndOfLine
  24. hepptho commented on Feb 4, 2022

    @hepptho

    Hmm, I'm on 7.2.1 / 20.04 too, and it works directly on command line as well as in profile.ps1.

    An alternative that works for me as well is:

    Set-PSReadLineOption -EditMode Windows

    The default EditMode on Linux appears to be Emacs, see also here for a (presumably) comprehensive list of things that should work in different edit modes. It's a nice reference.

    If that also doesn't work, then the only idea I have left - and that's a wild guess - is that the keys are hijacked by something else. That sometimes happens to me with shortcuts on Linux, but it would be weird with Home and End.
    You could try (if you haven't already) [Console]::ReadKey() followed by Home / End, and see what happens, and if it tells you anything.

  25. artisticcheese commented on Feb 4, 2022

    @artisticcheese

    Issue was seen only when using Remote Desktop Manager, not present at Windows command line, otherwise solution by Thomas Hepp (@hepptho) works as expected

  26. rkeithhill commented on Feb 5, 2022

    @rkeithhill
    Collaborator

    Thomas Hepp (@hepptho) RE Set-PSReadLineOption -EditMode Windows - thanks for that!!! I can't believe what a dope I've been. I've been fighting the PSRL key bindings on Linux/macOS for a while now. But my main machine is Windows. For some reason, it never occurred to me to check/change the PSRL edit mode. 🤦‍♂️

  27. yodasad commented on Feb 11, 2022

    @yodasad

    If that also doesn't work, then the only idea I have left - and that's a wild guess - is that the keys are hijacked by something else. That sometimes happens to me with shortcuts on Linux, but it would be weird with Home and End. You could try (if you haven't already) [Console]::ReadKey() followed by Home / End, and see what happens, and if it tells you anything.

    That was already done at the beginning of this thread on Sep, 2, 2019:
    #8869 (comment)

    PS /home/user> [System.Console]::ReadKey()
    
    KeyChar    Key Modifiers
    -------    --- ---------
           Escape         0
    
    PS /home/user> H
    

    It seems like pressing the Home button results in Escape following "H" and pressing the End button results in Escape following F, so I tried to do this:

    Set-PSReadLineKeyHandler -Chord Escape,H -Function BeginningOfLine
    Set-PSReadLineKeyHandler -Chord Escape,F -Function EndOfLine
    

    And it works, Home and End buttons started to work as expected, but unfortunately after that I cannot type capital "H" and "F" pressing Shift+H and Shift+F, they started to act as if I press Home and End buttons moving the cursor to the Beginning and the End of line.

  28. DTW-DanWard commented on Apr 1, 2022

    @DTW-DanWard

    None of the above worked for me on Mac (PS 7.2.2) but this did - hope it helps someone else.

    Create a new Terminal profile (or copy an existing) and add a Keyboard mapping for Home and End:
    Home
    Key: Home
    Modifier: None
    Send text: (using Mac keyboard, not external): CTRL+A
    This should produce Send text of \001
    End:
    Key: End
    Modifier: None
    Send text: (again on Mac keyboard, assuming no other modifier key changes): CTRL+E
    This should produce Send text of \005

  29. Clifra-Jones commented on May 13, 2022

    @Clifra-Jones
    Set-PSReadLineOption -EditMode Windows

    OMG! Thank you. This has been driving me nuts for months!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-ExternalThe issue is caused by external component(s).WG-Interactive-Consolethe console experience

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions