question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add a prePrompt_functions variable

See original GitHub issue

Description of the new feature/enhancement

it would be the same as zsh’s precmd_functions, which is a list of functions that are called before every prompt, this would allow module makers to add functions to the prompt without overwriting it.

Proof of concept

this allows any script to register a function to run before every command by simply doing $prePrompt_functions += "<function_name>"

$prePrompt_functions = @()
$prevprompt = $Function:prompt
function prompt {
	$prePrompt_functions | Invoke-Expression
	return $prevprompt.invoke()
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Jaykulcommented, Aug 28, 2021

PowerLine was just a proof of concept, see Why PowerLine.

The goal was always to convince the PowerShell team to change the default prompt function to

function prompt {
    -join $prompt.Invoke()
}

… and put the current prompt into that new global as three statements:

[System.Collections.Generic.List[ScriptBlock]]$Prompt = @(
    { "PS " }
    { $executionContext.SessionState.Path.CurrentLocation }
    { '>' * ($nestedPromptLevel + 1) }
)
1reaction
vexx32commented, Mar 26, 2021

IIRC @jaykul’s PowerLine module has some functionality like this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

prompt, variables and functions.
I want to get two number using prompt. Assign those number to two different variables, then use those two variables as parameters in...
Read more >
Is there a way of pre-populating Prompt Variables? | Automic ...
Hi, I have been asked by a user if there is a way of pre-populating prompt variables. What they have in mind is...
Read more >
Update variable in bash function and use it in prompt (PS1)
What I want to do is to call a function in PS1 to update a variable inside the function. Then I like to...
Read more >
Can I Put Prompt Inside of a Function in JavaScript?
Yes, it is possible to put a prompt inside of a function in JavaScript. Learn how to do it and see an example...
Read more >
What's the ZSH equivalent of BASH's ...
BASH supports a $PROMPT_COMMAND environment variable that defines a command to be executed before any first-level interactive prompt. I'm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found