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
Home, End, Ctr+Arrow don't work (Arch/Linux 4.20) #8869
Comments
This is most likely not a PowerShell problem. Try
I'm guessing it won't, in which case the problem could be with:
|
@lzybkr This is what I see on Ubuntu 18.04 (when I ssh in from Windows PS 7 and then start pwsh):
This is a real bummer as it makes moving around a command line painful. Here's the term info:
|
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 This shows the issue on 6.2.2 but I just tried PS7-preview.3 and it behaves the exact same way. |
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 :) |
/cc @daxian-dbw @SteveL-MSFT If the problem is in .Net Core we need to get a fix before .Net Core 3.1 LTS. @rkeithhill Could you please make the test with simple C# app which only output Console.ReadKey()? |
This seems most likely an issue in .NET Core. Agree with @iSazonov that a simple C# console app to repro would be ideal. |
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? |
@AndrewSav when PSReadLine is not involved as shown in @rkeithhill's example, pwsh has a simple ReadLine that doesn't do any translation of keys. It is whatever the .NET API returns. |
@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? |
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
.net core 3.0.100 program with Console.ReadLine
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. |
PowerShell uses ReadConsole P/Invoke on Windows that is power method. PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs Line 1517 in 70a74fb
Perhaps @PaulHigin could add more about ssh scenario. I already opened API request in CoreFX repo https://github.com/dotnet/corefx/issues/36175 long ago. |
I was able to repro this with ssh.exe we ship in Win10. However, after using just the ssh.exe from https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v8.1.0.0p1-Beta, it works as expected. So the issue appears to be in our Win32 port of ssh.exe. Work is happening to update the ssh in Windows, but it'll take time to be released. For now, you can just replace the ssh.exe from our GitHub release.
|
@SteveL-MSFT did you see my matrix above? When I tested it with ssh on windows I tested with:
It was exhibintg the problem on all of them, in addition Ctrl-Arrows did not work even without ssh. I'll try and re-test with 7 but while I'm doing this, are you sure, we are not jumping the gun closing it? It does not seem reasonable to request people use one certain flavour of SSH when so many are avialable. |
@AndrewSav in the cases where your .NET Core 3 app doesn't work, it would have to be an issue in the .NET Runtime repo |
@SteveL-MSFT which version of powershell did you test this with? |
Okay, after some testing it does not seem to be fixed. PowerShell 7.0.0-rc.1 running on ubuntu 18.04
The ctrl-arrows do not seem to work at all via ssh. Home/End work for some clients but not for other. Do you think there is an issue with powershell not suporting these? |
How come that this would be an issue with .net runtime for some cases but would not be for others? E.g. console app readline does NOT work for home/end over, say, with |
PowerShell (specifically PSReadLine) uses [console]::ReadKey(). That may differ from the ReadLine() api that you have as your test app. Try this instead: using System;
namespace readline
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ReadKey:");
var key = Console.ReadKey();
Console.WriteLine(key.Key.ToString());
}
}
} |
It does not work either way, but differently. When runnning |
Ctrl-UpArrow/DownArrow does not implemented in PowerShell on Unix. You could assign a handler for these keys in PSReadline. PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs Lines 1742 to 1749 in 70a74fb
|
Slightly offtopic. |
Yep, this is what this issue is about. Why is this closed? |
dotnet/runtime#802 tracks issues with |
It does not appear that this one is relevant. Firstly in never mentions ctrl-arrow keys, and secondly they seem to be reported as expected by |
@AndrewSav - got it - you should open an issue in https://github.com/PowerShell/PSReadLine for the lack of Ctrl+LeftArrow and Ctrl+RightArrow support in Emacs mode. Better yet, you could submit a PR - it's a trivial fix.
|
Bare with me, this has a point. I use windows 10 as my daily driver and have used windows as my desktop OS of choice since windows 95. I am a Microsoft fanboy through and through. I've been a developer using Microsoft technologies since the late 90s but have avoided Powershell because it's way too verbose for my liking. A coworker of mine turned me on to it again recently an I have fell in love with the power of the object oriented-ness (is that a word?). I am now a new fan of PowerShell and once you have a hammer everything looks like a nail, am-I-right? I knew Powershell has been cross-platform for a while now so I thought I'd try it out on some of our linux machines to automate some backup processes and it seemed to be working swell. Hot damn! I thought to myself this is great, one shell many OSes. Let's checkout the command line shell on Linux and maybe I can go with PS 100%. My glee turned to horror as I discovered that almost nothing works the same from the command-line as what it does in windows. An example is that auto-completion is very buggy with character casing and it doesn't cycle though the entries like it does on windows. PS continues to show all 148 (or whatever) entries as a giant block of text just like bash. "YUCK!" I say to myself upon this discovery, but it's easy to live with. Okay let's try something else.
Um... what user am I again? The default prompt doesn't include the username on linux where the user means everything. This is a windows-ism that shouldn't have been the default in linux. But I think that is changeable, let's move on. As I was exploring I discovered many of the keyboard shortcuts that I use in bash on linux and in powershell on windows DO NOT work for powershell in linux. This is a show stopper for me and it completely decimates my productivity. This has to be a config issue on my machine right? Wrong. When I discover a trail of issues going back about 2.5 years (at this point) that were closed for technicalities or because of the "it's not my problem" syndrome, I was crushed. How could a company that says it's product is cross-platform let something like this slip for over 2 years? The responses from the Microsoft team members among this trail of issues has left me dejected. It's issues like this one that really show me how (un)dedicated Microsoft is to cross platform technologies. This ongoing behavior I see from the Powershell team has really made me question whether a future issue that affects my powershell scripts on linux may go unfixed for over 2 years. I cannot justify this with my management. It's my decision to make, but if it breaks, it's my problem to fix and I cannot trust you Microsoft. |
@AgSync-Aaron You could learn how to customize PowerShell prompt and PSReadline - I guess you have no idea what the latest version of PSReadline can do. |
You completely missed my point. Typical. Thank you for your snarky elitist comment. I was telling a story of my journey of how PS command line for linux isn't perfect and I'm willing to overlook almost all of those issues. But as a product that claims to be cross-platform, it misses the boat on basic core usability. This is a show-stopper for me and clearly many other people who have commented on these series of issues that keep getting closed. I love MS products and have made a career out of using them. I have invested a lot of my time the past couple months in learning powershell for nothing. This issue is STILL an issue 2.5 years later. The point is that I cannot trust Microsoft to be good stewards of cross-platform technology when they let something this basic go unfixed for so long. If you'd like to have a serious conversation about Microsoft's choices here I'm game, but leave the condescending comments at the door. |
Sorry, I didn't try to offend you. My efforts here are to make PowerShell better.
PowerShell capabilities are based on .Net capabilities. There are fundamental contradictions in how different OSes work. It is not easy to get over it. Net team is actively planning next 6.0 milestone and you can discuss this and vote in .Net Runtime repository so as to help them prioritize. |
I accept your apology, thanks. I had always figured there was a way to customize the prompt, I wasn't concerned about that. That was one of those imperfections that all software has and that I wasn't concerned about it. It was just a data point in my journey of Powershell discovery that I was trying to share. I was trying to share my experience and how excited I was about the prospect of having one shell and one scripting language across OSes. And how that excitement turned to disappointment over missing basic functionality. As as customer, frankly, I don't care who's team is responsible. Microsoft is my software vendor and my company pays them a lot of money. If a member of our support team told our customer "sorry, that's not my problem" and hung up on them. We would probably lose that customer. I am trying to let Microsoft know that is how I was made to feel here by reading these issues and seeing them dismissed out of hand. I am trying to standardize the languages that my company uses to manage our infrastructure. Microsoft says their "command-line shell" product is "cross-platform" but fails to pass some minimum requirements due to a bug. In all due respect, I cannot recommend ANY product, no matter the vendor, if what we consider basic functionality to be non-existent or buggy. I truly have honest concerns about using cross-platform powershell. This issue is over 2 years old and has been passed off to another team at Microsoft and that issue that is over FOUR years old! If I run into a bug in my critical infrastructure that is deemed to be "some other team's" fault. Am I going to have to wait two years for a fix? |
Yes, this has been an uphill battle with a lot of finger pointing, and the end result that interactive experience on Linux via SSH from Windows is in a shape, where it cannot be used as the default command prompt. This is very disappointing and frustrating. "It's PSReadline!", "No, it's PowerShell!", "No it's .NET!". To be completely honest I'm still not convinced that it's .net because as far as I can see the .net bit works as long as it's not called from PowerShell. Yet the issue was closed. I supplied a lot of tests above but all I got in response is asking for more tests and no evidence that someone tested it and it worked differently, no steps to reproduce that were ever published. In the end we have nothing else to do but to accept, that this is how PowerShell management chose to engage with the community. This is not satisfactory, but it is what it is. |
After some investigations i found that Powershell (.NET) uses ncurses, so i got Home and End working by editing Terminfo for the used $TERM (xterm for me) by
After relogin Home and End did work in pwsh as expected. I did not look for Ctrl-Arrow, but maybe this can be fixed in a similar way... next one please ;-) Peter |
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.
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 |
@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. |
@AndrewSav @steven-willard
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. |
@AndrewSav @steven-willard @npodbielski
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.
Which is very sad, because PS is more powerful than bash in many ways.
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 |
There are too many comments in this thread... I cannot figure it out, why was the issue closed? |
I've found a workaround: for Home and End you can use Ctrl+A and Ctrl+E respectively. |
https://twitter.com/artisticcheese/status/1485698470791028741 leave comments under tweet to tell Microsoft that we still care.
|
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. |
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 |
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. |
Issue was seen only when using Remote Desktop Manager, not present at Windows command line, otherwise solution by @hepptho works as expected |
@hepptho RE |
That was already done at the beginning of this thread on Sep, 2, 2019:
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:
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. |
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: |
OMG! Thank you. This has been driving me nuts for months! |
Steps to reproduce
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
Environment data
I used yaourt on Arch to install.
The text was updated successfully, but these errors were encountered: