Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortening my prompt in Zsh

Tags:

I'm having a lot of trouble getting zsh to shorten my prompt. I'm currently using zsh with the agnoster theme and oh-my-zsh package manager.

My prompt currently gets annoyingly long during work, usually around 110 characters, taking up the entire length of my terminal, which is just not very aesthetically pleasing.

I've looked at a few other people's .zshrc's and attempts to modify their prompt, but nothing seems to work in mine. I've tried copying many, many things into my .zshrc and have seen no effects.

My most recent attempt was to try to copy the prompt block from https://stackoverflow.com/a/171564/2416097

Nothing. Even when I disabled my theme while having this block included, the prompt is still at full length.

Additionally, I can't seem to find any simple or straightforward guides on how to format my prompt in the first place. Most of the results I found while searching only yielded long format strings without explanation or instruction on use.

Any help appreciated!

like image 529
bgenchel Avatar asked May 17 '16 22:05

bgenchel


People also ask

How do I edit my zsh prompt?

To customize the ZSH prompt, we need to modify the prompt= variable inside the . zshrc file. We can populate the prompt variable with various placeholders, which will alter how the ZSH prompt appears.

What is zsh prompt?

The default prompt for zsh is: phoenix% echo $PROMPT %m%# The %m stands for the short form of the current hostname, and the %# stands for a % or a # , depending on whether the shell is running as root or not. zsh supports many other control sequences in the PROMPT variable.


1 Answers

Old question, I know, but as an alternative solution I just discovered powerlevel9k, an extension of agnoster (they appear practically identical bar a fair few tweaks), which has this functionality built in.

Just set it as your zsh theme, then in .zshrc set

POWERLEVEL9K_SHORTEN_DIR_LENGTH=2

which ensures that only two directories are listed.

Alternate options are outlined in the readme.

like image 95
Charlie Taylor Avatar answered Sep 21 '22 15:09

Charlie Taylor