After shitting on the Rust programming language in my previous post, I was forced to use a Rust alternative for my shell prompt, since what I was using in Bash is slow beyond belief. This isn’t due to my implementation being slow, but because Bash itself is slow. I should mention that comparing Bash and Rust isn’t fair, as they’re meant to be used in different contexts. This post isn’t going to be very informative or explanatory; it’s more about documenting my experience using Starship and what I did beforehand.
This isn’t the first time I’ve used Starship. After seeing a post on /g/ complaining about the slowness of a shell prompt written in Bash, I briefly installed and tried Starship. However, I spent very little time figuring it out. The extent of my trial was copying my PS1 and whatever it sources from .bashrc, pasting it into an LLM, explaining what I wanted, and receiving something that didn’t run. Since I didn’t read the documentation on the Starship site, I couldn’t debug the errors and eventually gave up, returning to my Bash-configured prompt with significantly higher latency.
I don’t know what prompted me (heh) to give it another shot, but it happened in the late hours of the night. I should’ve been asleep hours ago, but I fixated on fixing the high latency issue and gave Starship a fair try. For the next couple of hours, I read the documentation and tried to figure out how strings work in TOML.
I think Starship overall has pretty good documentation, but the website it’s on is very bad. Scrolling on that site sucks - no, I will not elaborate. TOML is minimal, but I wouldn’t call it obvious. One of the things I spent the most time on was the actual format string. I was using backslashes to escape some special characters used in the format, but when I did that, I couldn’t put the different modules on separate lines for clarity. Eventually, I gave up on that approach and moved on to creating custom modules that fulfilled this purpose.
Right now, my prompt looks identical to what it looked like before, but I have extra functionality - like showing which language the project is in, more detailed Git state (more Git-related info in general), etc. This was my PS1 before Starship:
PS1="[\u@\h \W]\$ \$(__git_branch)\$(__git_state)"
I omitted the colors from the command, but I was exporting certain colors (like red, blue, yellow, purple, etc.) in bold using ANSI escape sequences and then using them in PS1.
I had a Bash script in my Git config folder for showing Git-related information - like branch and state info - which I sourced in .bashrc:
source "$XDG_CONFIG_HOME/git/git-prompt.sh"
If you were to ask me to explain what the Bash script does, I couldn’t really explain it, as I wrote it quite a while ago and copied parts of it from scripts I found on the internet.
https://github.com/NecRaul/gitconfig/blob/main/git-prompt.sh
Now, I have a pretty comprehensive starship.toml file, which not only reduces latency significantly but is also easier to customize.
https://github.com/NecRaul/dotfiles/blob/main/.config/starship.toml
I recommend Starship to everyone. With a little configuration, you can replace your PS1 - however simple it may be - with this utility and go about your day.