Skip to content

How to make a prompt so that its length is proportional to terminal width and pad the prompt with dots if the length of the prompt is less than n #9823

Closed Answered by faho
blueray453 asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, I'm not going to reverse engineer your sigil soup - if you want hieroglyphs translated ask Dr Jones, next floor down.

Instead, here's what you need:

https://fishshell.com/docs/current/cmds/string.html - which has a string pad command that can pad a string to a given width.

https://fishshell.com/docs/current/cmds/math.html - to do calculations

https://fishshell.com/docs/current/cmds/fish_git_prompt.html - that's our "git_ps1"

Put it all together in a fish_prompt function, something like

function fish_prompt
    # Get the actual prompt together - here we use $(prompt_pwd),
    # which shortens it with ~ instead of $HOME and only one char per component.
    # We could also just use $PWD

Replies: 4 comments 11 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by blueray453
Comment options

You must be logged in to vote
1 reply
@faho
Comment options

Comment options

You must be logged in to vote
5 replies
@blueray453
Comment options

@faho
Comment options

@faho
Comment options

@blueray453
Comment options

@faho
Comment options

Comment options

You must be logged in to vote
5 replies
@faho
Comment options

@faho
Comment options

@blueray453
Comment options

@blueray453
Comment options

@faho
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants