www.emsdn.com
Class Profile: Home »» Unix/Linux [Unix/Linux] under "Unix/Linux" »»» bash prompt stuff
bash prompt stuff
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:
/ gets changed to
so the prompt would look like:
username$
thanks in advance
No. 1# | By Developer Tags User at [2008-5-4] | size: 821 bytes
2005-07-12, juicymixx@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:
/ gets changed to
ng_path/going/to/some_place
so the prompt would look like:
username$
PRMPT_CMMAND='if [ ${#PWD} -gt 30 ]
then PS1="-\h:${PWD: -27}\u$ "
else PS1="-\h:\w- \u$ "
fi'
No. 1# | By Developer Tags User at [2008-5-4] | size: 1091 bytes
Tue, 12 Jul 2005 15:04:42 -0700, juicymixx@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:
/ gets changed to
ng_path/going/to/some_place
so the prompt would look like:
username$
If you have bash3, then the following will do what you want, after you put
in a few more question-marks.
PS1='-\h:${PWD/#???*/${PWD#${PWD%???}}}- \u\$ '
The first set of question-marks determine the length where the prompt is
changed, and the second set determine how many characters of the name are
displayed.
No. 1# | By Developer Tags User at [2008-5-4] | size: 1079 bytes
Tue, 12 Jul 2005 15:04:42 -0700, juicymixx@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:
/ gets changed to
ng_path/going/to/some_place
so the prompt would look like:
username$
If you have bash3, then the following will do what you want, after you put
in a few more question-marks, and change the number
PS1='-\h:${PWD/#???*/${PWD: -9}}- \u\$ '
The question-marks determine the length where the prompt is changed, and
the -9 determine how many characters of the name are displayed.
No. 1# | By Developer Tags User at [2008-5-4] | size: 222 bytes
Thanks for all the responses guys
I ended up going with Chris F.A. Johnson's solution. I like the idea
of having the PRMPT_CMMAND do all the checking 'work'. Thanks
Chris!
No. 1# | By Developer Tags User at [2008-5-4] | size: 337 bytes
juicymixx@mailinator.com wrote:
hey, I'd like to customize my bash prompt a bit
Let another script do the work for you
http://bashish.sourceforge.net # "bashish.bash"
# "Dotfile
Generator.tcl"
# "ibpconf.bash"
For bash profiles in general, a fine place to look is:
=Brian
Unix/Linux Hot!
Unix/Linux New!
Copyright © 2008 www.emsdn.com • All rights reserved • CMS Theme by www.emsdn.com - 0.219