-
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Usage of default prompt but with custom side effects in prompt function #501
Comments
In theory you could do something like:
Just keep in mind if any "output" returned by this would get displayed before the default posh-git prompt, hence the redirect to $null. You might notice a bit of slow down in your prompt display in directories containing a .nvmrc file. |
will this be executed more then once though? |
Be careful to use single quotes when supplying the string. If you use double quotes, any variables / subexpressions i.e. |
@felixfbecker What if we created another global variable (like function prompt {
# ... script to do stuff like switch node versions
&$GitPromptScriptBlock
} I've prototyped this and it works fine in my testing. I might include this in the upcoming BTW I wonder if we should call this variable |
Or, going the other direction, we could add |
We could actually do both. Allowing users to inject custom script via a ScriptBlock would be handy. But exposing |
👍 |
What if we made this change just for 1.0.0? @felixfbecker is on PS Core, so he'd be covered. |
@felixfbecker Would you be willing to try out the function prompt {
# ... script to do stuff like switch node versions
if ($GitPromptScriptBlock) { &$GitPromptScriptBlock }
}
import-module ~/github/posh-git/src/posh-git.psd1 I added in the guard just in case you remove the posh-git module. |
I'm curious why it is a dynamic script block and not just a function like Checked out the branch to test but struggling with #486 |
Because we assign that scriptblock to the prompt function i.e. that's how we "set" the prompt function. Set-Item Function:\prompt -Value $GitPromptScriptBlock |
RE #486 - try setting: $global:GitPromptSettings.DefaultPromptSuffix = '`n$(''>'' * ($nestedPromptLevel + 1)) ' That is supposed to get rid of the double prompt. Of course, PSReadline |
So PS Core 6.0.0-rc2 solved the readline issue. function prompt {
&$GitPromptScriptBlock
}
Import-Module ~/git/posh-git/src/posh-git.psd1 I get this prompt:
But if I add: function prompt {
Set-NodeVersion
&$GitPromptScriptBlock
}
Import-Module ~/git/posh-git/src/posh-git.psd1
Import-Module nvm I get nothing:
|
Does |
Ah, |
I think this is therefor solved :) |
System Details
Issue Description
I want to customize my
prompt
function so that it checks whether the current directory has an.nvmrc
file and switches Node versions depending on that. But I also want to keep the default git prompt. Is that possible?The text was updated successfully, but these errors were encountered: