Friday, July 15, 2005

customize my bash prompt

hey, I'd like to customize my bash prompt a bit...

currently I have:
PS1="-\h:\w- \u$ "

the problem I have is sometimes I get pretty deep into my directory
structure, and some of my directory names are pretty long. Is there
some way to change the \w in my prompt to:
1) if the directory structure is less than 30 characters, just display
it
2) if the directory structure is more than 30 characters, change it to
display three dots (like an ellipsis) and the last 27 characters of the
path
for instance:
/some_really_long_path/going/to/some_place gets changed to
...ng_path/going/to/some_place

so the prompt would look like:
-hostname:...ng_path/going/to/some_place- username$

thanks in advance...

Reply

On 2005-07-12, juicym...@mailinator.com wrote:

> hey, I'd like to customize my bash prompt a bit...

> currently I have:
> PS1="-\h:\w- \u$ "

> the problem I have is sometimes I get pretty deep into my directory
> structure, and some of my directory names are pretty long. Is there
> some way to change the \w in my prompt to:
> 1) if the directory structure is less than 30 characters, just display
> it
> 2) if the directory structure is more than 30 characters, change it to
> display three dots (like an ellipsis) and the last 27 characters of the
> path
> for instance:
> /some_really_long_path/going/to/some_place gets changed to
> ...ng_path/going/to/some_place

> so the prompt would look like:
> -hostname:...ng_path/going/to/some_place- username$

PROMPT_COMMAND='if [ ${#PWD} -gt 30 ]
then PS1="-\h:...${PWD: -27}\u$ "
else PS1="-\h:\w- \u$ "
fi'

--

0 Comments:

Post a Comment

<< Home