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

Doesn't work with Cmder #45

Closed
michaeljones32 opened this issue Jun 19, 2018 · 11 comments
Closed

Doesn't work with Cmder #45

michaeljones32 opened this issue Jun 19, 2018 · 11 comments
Milestone

Comments

@michaeljones32
Copy link

Installed successfully and works with regular powershell, but when using cmder I get this error:

Cannot write to function prompt because it is read-only or constant.
At C:\Users\MJ2\Documents\WindowsPowerShell\Modules\ZLocation\0.3.0\ZLocation.psm1:56 char:9
+         $function:prompt = [ScriptBlock]::Create($newPrompt)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (prompt:String) [], SessionStateUnauthorizedAccessException
    + FullyQualifiedErrorId : FunctionNotWritable
@vors
Copy link
Owner

vors commented Jun 19, 2018

hm, interesting, why cmder makes the promp function RO?

@michaeljones32
Copy link
Author

What is RO?

I was just running z and it threw that, just running standard cmder, never had any issues like this before

@Kethku
Copy link

Kethku commented Jun 19, 2018

RO stands for read only.

@vors
Copy link
Owner

vors commented Jul 11, 2018

I don't have a windows machine at the moment, if anybody can investigate and confirm this isssue, I'd very much appreciate it.

@Snaptags
Copy link

Snaptags commented Jul 11, 2018

Yes, I can confirm this. But as far as I am concerned this is a cmder problem. Handling the prompt itself is one of its main features:

…and a custom prompt layout.
https://github.com/cmderdev/cmder

This is from the profile.ps1 cmder uses for powershell:
<# This scriptblock runs every time the prompt is returned. Explicitly use functions from MS namespace to protect from being overridden in the user session. Custom prompt functions are loaded in as constants to get the same behaviour #>

Maybe editing the profile could work around the problem…

@vors
Copy link
Owner

vors commented Jul 12, 2018

Hm, looks like they left PrePrompt / PostPrompt function for customization. It's probably easier to special-case cmder prompt (i.e. catch the error while changing prompt) and use one of this functions instead.

https://github.com/cmderdev/cmder/blob/4655888690cd807cd24b082509c1e65e0a4cca38/vendor/profile.ps1#L175

@cspotcode
Copy link
Contributor

#48 offers a solution.

# In your profile:
Import-Module ZLocation -ArgumentList @{Register = $false}
Function PrePrompt {
    Update-ZLocation
}

@vors
Copy link
Owner

vors commented Aug 26, 2018

@cspotcode thank you for looking at it!
I think we can make UX here more seamless by special-casing cmder and handling it transparently for people.

@glucas
Copy link

glucas commented Aug 27, 2018

@cspotcode Thanks, your PR works great for me. Here's the snippet I've got working in my cmder user-profile.ps1 (note the $pwd is important!):

[ScriptBlock]$PrePrompt = {
    Update-ZLocation $pwd
}

@vors vors added this to the 0.4.0 milestone Sep 7, 2018
@vors vors removed the help wanted label Sep 7, 2018
@vors
Copy link
Owner

vors commented Sep 8, 2018

Hm, actually it was easier than I though: hint to use -Force was below https://github.com/cmderdev/cmder/blob/4655888690cd807cd24b082509c1e65e0a4cca38/vendor/profile.ps1#L211

@vors
Copy link
Owner

vors commented Sep 8, 2018

Fixed

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

6 participants