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
-
I am thinking of transitioning to fish, For this I need the prompt which I am currently using with zsh. Here is the details:
Here, __git_ps1 is taken from by https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh It looks like: More about this prompt can be found on https://unix.stackexchange.com/a/604212/206574 and https://unix.stackexchange.com/a/370276/206574 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
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 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
# fish_git_prompt does the git display
set -l prompt "$(fish_git_prompt)$(prompt_pwd)%"
# Tell string pad to pad it out to the given width with dots
# (it is smart enough to remove any color escapes from the calculations,
# like what fish_git_prompt will print)
# math's `-s0` makes it truncate to int
string pad -c . -w (math -s0 "$COLUMNS * 0.35") $prompt
end |
Beta Was this translation helpful? Give feedback.
-
I checked your code. Algorithmically i think this is what I need. But when running, I am getting an error.
|
Beta Was this translation helpful? Give feedback.
-
I am using Zorin. It says:
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
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