Powershell: Home key is not taking me to beginning of the line

Created on 18 Aug 2016  路  12Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Type any command and then press Home key on keyboard.

Expected behavior

Cursor should go to the beginning of the line.

Actual behavior

~ character is created.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.9
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

All 12 comments

This is likely a problem with your TERM setting and how Console.ReadKey() works (which has bleeding-edge support for Linux!).

If you can track it down, please feel free to file bugs with https://github.com/dotnet/corefx. I _think_ that .NET Core's implementation is technically correct, meaning that I don't think it handles TERM settings being incorrect but close, and it should probably try to "do what I mean" when it receives a HOME code for a termcap entry differing from the user's TERM.

Agree with @andschwa. This was observed awhile ago in issue https://github.com/PowerShell/PowerShell/issues/421. Perhaps we should reopen that issue?

I'm using Bash on Windows to SSH into an Ubuntu box in Azure (where PowerShell is installed). Expected behavior is happening from the bash shell before launching the powershell command.

What TERM setting should be adjusted to resolve this?

What TERM to use is entirely up to your terminal emulator (your Windows console), we'd have to dig into the WSL docs to determine that. If I had to hazard an absolute guess, maybe vt100?

Sorry, I was wrong - I'm using Putty to get into the Ubuntu VM on Azure. On the machine where PowerShell is installed I have xterm seems to be used (echo $TERM results in xterm).

I'm outside my area of expertise here but if it were a TERM issue wouldn't the same behavior happen on both the native bash shell and in PowerShell? That is not the case - before launching powershell I'm able to use the Home and End keys as expected however when I'm in powershell both just display ~ character.

Bash uses GNU Readline, which is far more mature than .NET Core's Console.ReadKey().

For PuTTY, I recommend https://sanctum.geek.nz/arabesque/putty-configuration/

(Bash on Windows is now very confusing terminology!)

When using Putty to connect to the Ubuntu box I'm getting this (note the ~~ characters after get-date, created by pressing Home and End buttons respectively):

ored@ubuntu:~$ echo $TERM
xterm
ored@ubuntu:~$ powershell
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS /home/ored> get-date~~

When I use Bash on Windows to SSH into the box I'm getting a different behavior (note the HF characters after get-date, created by pressing Home and End buttons respectively):

ored@ubuntu:~$ echo $TERM
xterm-256color
ored@ubuntu:~$ powershell
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS /home/ored> get-dateHF

Putting 'putty-256color' into my Terminal-type string setting (per your link) in Putty did make Home and End work now within powershell on my remote host as expected.

Awesome, I'm glad that worked out.

I'm using xshell and I change the Terminal Type to putty-256color to solve this problem

export TERM=putty-256color works for me in the following scenario:

  1. Start PowerShell Core 6 on Windows client
  2. SSH into Ubuntu (bash opens)
  3. Start PowerShell Core 6 on Ubuntu
    ...meaning no actual Putty involved. Other TERM options seem to fail.
Was this page helpful?
0 / 5 - 0 ratings