starship
starship copied to clipboard
Add transient prompt configuration option
Feature Request
Is your feature request related to a problem? Please describe.
Currently, every time a command is entered, the prompt is recreated on the line below. This is normal behavior, but arguably can look cluttery when the prompt extends beyond a single line.
Describe the solution you'd like
The solution I propose is a configuration option for a transient prompt. The prompt would appear to stay on one line while previous commands would appear as normal. Here's what this looks like in powerlevel10k. I don't know how to implement this, nor do any particular drawbacks come to mind. Powerlevel10k's implementation could be a good place to look for inspiration.
Very cool feature but difficult to implement. Powerlevel10k code is virtually impenetrable so I'll give a few pointers that should help you if you decide to implement it in Starship.
There are two distinct approaches to implementing this feature.
- Truncate prompt in
zle-line-finish
, restore inprecmd
. See this post. - Hook
zle-line-init
and wrap everything inrecursive-edit
. See this post.
The first fails when you interrupt modal widgets with Ctrl-C. See this bug report and my description here.
The second suppresses job monitor notifications as if no_notify
option was in effect. See the bottom of this post.
Both of these problems make the simple implementations unusable. After banging my head against this for a month I managed to fix the first implementation. The code is quite hairy and I haven't posted it anywhere yet. The idea is to stop trying to prevent overzealous prompt truncation on Ctrl-C and instead quickly recover the original prompt when it becomes apparent that it shouldn't have been truncated in the first place. This requires wrapping all zle widgets and deferring a function with zle -F
on a ready file descriptor.
In addition, both solutions trigger bugs in zsh: bug 1, bug 2, bug 3. The first two bugs cause zsh to segfault but thankfully there are workarounds -- follow the trail from the links I posted above. I wasn't able to find a workaround for the third bug but it triggers in a more limited set of circumstances and doesn't crash zsh, so it's not that terrible. If you find a workaround for it, please let me know.
romkatv gave base level sample code for the two implementations here: https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840
Cmd's Clink also has native support for transient prompts - https://chrisant996.github.io/clink/clink.html#transient-prompt
Would be cool if Starship can leverage this one day ✌
Cmd support (through Clink) was added in #3277. It included a transient-prompt and a transient-right-prompt, but later it was removed because as of now it was a single shell functionality. For anyone else looking to use this, I have pasted the relevant documentation here.
TransientPrompt and TransientRightPrompt in Cmd
Clink allows you to replace the previous-printed prompt with custom strings. This is useful in cases where all the prompt information is not always needed. To enable this, run clink set prompt.transient <value>
(you need to do this only once) where <value> can be one of:
-
always
: always replace the previous prompt -
same_dir
: replace the previous prompt only if the working directory is same -
off
: do not replace the prompt (i.e. turn off transience)
Make the following changes to your starship.lua
to customize what gets displayed on the left and on the right:
- First, declare a custom prompt filter
my_custom_starship
after the Starship initialization command. Define it to return the prompt string as-is. - By default, the left side of input gets replaced with
>
. To customize this, define a new function calledmy_custom_starship:transientfilter
. This function receives the current prompt as a string that you can utilize. - By default, the right side of input is empty. To customize this, define a new function called
my_custom_starship:transientrightfilter
. This function also receives the current prompt as a string that you can utilize.
In the end it will look something like this:
-- Initialize Starship
load(io.popen('starship init cmd'):read("*a"))()
-- Define a custom prompt filter
local my_custom_starship = clink.promptfilter(10)
function my_custom_starship:filter(prompt)
return prompt
end
-- Display Starship's `character` module on left side
function my_custom_starship:transientfilter(prompt)
return io.popen("starship module character"
.." --keymap="..rl.getvariable('keymap')
):read("*a")
end
-- Display the time at which the last command was started on right side
function my_custom_starship:transientrightfilter(prompt)
return io.popen("starship module time"):read("*a")
end
@rashil2000 does this still work?
Haven't used it in a while, what error did you face?
I haven't tried it yet
any progress considering the transient prompt?
@Tummetott it's not dependent on Starship, it's a feature of the respective shell
no it works with my shell with other prompts
I would love this feature to be supported in Starship. Oh My Posh seems to be able to do it in cmd (as discussed above), fish, zsh and powershell, so I would hope it to be possible to properly integrate it?
@chipbuster I've got transience working for Starship in PowerShell (thanks to Oh-My-Posh). Since this functionality is now available for more than one shell (Cmd, and now PowerShell), will it be acceptable in the Advanced Config section of docs?
@rashil2000 Sure!
Quick disclaimer: I've been considering reorganizing the docs so that all the shell-specific stuff is in one place, but I think we can deal with that when we need to.
This missing feature still holds me back to switch to Starship. Would be amazing to see this getting implemented. 🤗
PR is up #4143
I'm not a very experienced fish user, but if anyone is willing to take a shot at it they can checkout my comment in the PR.
Reading the linked merged pr it seems it only partially implements that feature request (not for zsh, etc.).
pr for zsh https://github.com/starship/starship/pull/4205
Reopening this, we have added this feature for fish but no other shells, let's keep this open at least until the existing PR for zsh has been merged.
Reopening this, we have added this feature for fish but no other shells, let's keep this open at least until the existing PR for zsh has been merged.
There hasn't been progress in the Zsh PR, is there a need for contributors? Putting a tag for "contribution-needed" could help?
Unfortunately nobody is confident enough to implement this with all its edge cases