Skip to content
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

PSReadLine doesn't work with ISE #401

Closed
mikemaccana opened this issue Jun 27, 2016 · 6 comments
Closed

PSReadLine doesn't work with ISE #401

mikemaccana opened this issue Jun 27, 2016 · 6 comments

Comments

@mikemaccana
Copy link

mikemaccana commented Jun 27, 2016

With Import-Module PSReadLine in my $profile, opening a new tab in ISE doesn't seem to give a persistent bash history (which I understand is one of the benefits of psreadline)

This looks like a known issue - https://github.com/lzybkr/PSReadLine#post-installation mentions checking for the host type to see if it's ConsoleHost - but it doesn't say why. Having history on tabbed powershell like ISE provides (without all the extra stuff in conemu) would be great.

Get-InstalledModule shows PSReadline 1.2. Other details below:

Name             : Windows PowerShell ISE Host
Version          : 5.1.14372.0
InstanceId       : 13c30fd2-8d32-4e8c-8050-7e9af855d80b
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Thanks for listening - I'm grateful for any help here!

@gwojan
Copy link

gwojan commented Jun 27, 2016

PSReadLine doesn't support the ISE which doesn't have a true console (conhost.exe) behind it.

Checking for the host is to prevent loading in the ISE.

@mikemaccana
Copy link
Author

Thanks @gwojan. Is there any way psreadline could work with what ISE provides, or should I find a different way to handle persistent history?

@gwojan
Copy link

gwojan commented Jun 27, 2016

There are a number of things you could do.

There is a module called HistoryPx here on GitHub by @KirkMunro you could try out. If you have the PackageManagement module available it's as easy as Install-Module HistoryPx.

You could also configure your $Profile to save your history on exit and then read it back in during startup. This has the advantage of working in the ISE and the standard PowerShell console.

When I have my work machine available I can send you the commands I use to configure the the OnClose event for exporting the history if you'd like.

@gwojan
Copy link

gwojan commented Jun 28, 2016

@mikemaccana Try adding this to your profile:

$historyPath = "$env:USERPROFILE\PowerShell_History.xml" 
if (Test-Path -Path $historyPath) {
    Add-History (Import-Clixml $historyPath)
}
else {
    Write-Warning "$historyPath does not exist. Unable to restore command history"
}

Register-EngineEvent -SupportEvent PowerShell.Exiting -Action { Get-History | Export-Clixml -Path $historyPath -Encoding ASCII}

Now every time you type exit at the command line to close PowerShell or click the red X the registered script block will execute and save your history.

Sadly, the PowerShell console is not an application that responds to Windows shutdown notifications so the event handler doesn't execute on Windows shutdown and I've never really experimented with the ISE because I almost never use it.

@lzybkr
Copy link
Member

lzybkr commented Jun 28, 2016

Console applications can execute a handler on Windows shutdown, PSReadline actually needs a handler so history can be saved before the process is killed by Windows, see:

https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/ReadLine.cs#L238

@lzybkr
Copy link
Member

lzybkr commented Jun 28, 2016

I'm closing this because I have no plans to add support to the ISE.

There is significantly more effort being spent on PowerShell editor services which supports multiple editors, and I expect more editors to adopt the console like VSCode does.

This isn't to say it will never happen, but unless someone else can pick up this work, it's not something I'll can find the time for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants