Image of the glider from the Game of Life by John Conway
Skip to content

More ZSH Prompt Love

Ever since discovering ZSH 3 years ago, I've been addicted, but it wasn't until a good 2 years into using the prompt on a daily basis that I decided to do some radical work with my prompt. I've blogged about this before a couple times, making improvements along the way: post 0, post 1, post 2, post 3. Check out those posts if you're interested in what I've done to the prompt, and extra screenshots.

At the Utah Open Source Conference, I gave a BOF on Unix shells. The turnout was good, and we had a great discussion. I presented on my default prompt for ZSH, showing all the hidden features of the prompt. However, I had forgotten that I had removed battery status from my prompt, because I was depending on APM, which is no longer compiled in the kernel. A couple people have asked me since then why I'm depending on APM and not ACPI. I don't have an answer, other than that was just what I coded. So, last night, I put up an ACPI implementation, and it works great. As with the APM implementation, if the battery percentage is less than 15%, the percentage display is red. If it's less than 50% but greater than 14%, it's yellow, and if it's less than 100% but greater than 49%, it's blue. If it's 100%, or the tool "acpi" is not installed, then it doesn't show up. Here's a screenshot below:

Battery Percentage in ZSH prompt

While hanging out in our local LUG channel for the Ogden Area Linux Users Group, I got talking with Seth about prompts. He decided to change his, including adding the dog from Nethack randomly "moving" in the prompt. He also mentioned changing the color of the path if the present working directory was not writable. I really liked this idea, and decided to implement it in my prompt. Here's a screenshot of that in action:

Path color change in ZSH prompt

I change the path color to yellow if the present working directory is not writable, as it's noticeable enough to catch your attention, but subtle enough to not get in the way, and be distracting.

As usual, if you want the source, here it is. Yes, it's public domain, as mentioned in the code, so have at it.

{ 7 } Comments