So I'm looking for a way to shorten the path in the prompt if it reaches a defined length, such as:
user1@localhost:~/Pictures/awesome_trip/
Would be fine, but if we cd into more sub-directories such as:
user1@localhost:~/Pictures/awesome_trip/first_day/mikes_camera/funny_pics
I would like the prompt to change to
user1@localhost:/.../funny_pics
I know how to change the prompt in the .bashrc
I was wondering if there is a way to make it dynamically such that I can get the current length of the working dir and check the length, and change the prompt. something along the lines of:
CUR_PROMPT=$(pwd); # get the working dir
CUR_PROMPT_LENGTH={#CUR_PROMPT}; # get the length
if[ $CUR_PROMPT_LENGTH -gt 20 ]; then
if prompt is long, render shorter version
PS1='\u@\h:...\w:$';
else
else render long version
PS1='\u@\h:\W:$'
Hopefully there is way to do this, Thank you for your answer.
PROMPT_DIRTRIM
mechanism for that - see How can I shorten my command line (bash) prompt? – steeldriver Aug 28 '21 at 01:55