Shell – How to display only the current directory while using powerline in the terminal prompt.

promptshell

Recently I installed the Powerline in the linux to enhance the look and feel of my terminal. It works great, however, it display 3 levels of directories in the prompt while traversing. Consider below example

unikx> ...>Dir1>Dir2>Dir3

where unikx is my username and Dir3 is my current working directory. The problem is, I have a habit of giving long names to directories. So due to above behaviour of Powerline showing 3 levels, I dont have enough space on that current line to write my commands and eventually my commands appear in the next line which I dont like.

So how do I customize powerline to show only 2 or current dir in the prompt like below:

unikx> ...>Dir3 

or

unikx> ...>Dir2>Dir3

Thanks.

Best Answer

I think the setting you're looking for is in something like

<powerline_install_dir>/config_files/themes/shell/__main__.json

on this line:

"dir_limit_depth": 3

(Note that your installation may be different from mine so you might have to search for the file.)

See Powerline quick setup guide. This reddit post might also help. (If you're in a hurry edit that file directly.)

FYI, a simple alternative is the powerline command's --width flag which takes max width of the prompt in columns/characters. E.g. powerline --width 40 .... This will dynamically resize segments of the prompt as needed which usually means shrinking the path segment.

You probably won't know if you like it until you try it. That way you can see exactly how it behaves for different console widths, different paths, with whatever other segments you are displaying, etc.

I couldn't find a straightforward way to set this but looking at the code it seems that setting COLUMNS=X (X is desired width) in your environment before invoking the powerline.sh startup script will do the trick.