Search this site


Metadata

Articles

Projects

Presentations

yes, even more ksh prompt fun...

So the next thing that bothered me about my prompt was the fact that sometimes I'd have some crazy long directory filling up 90% of the line - this was a bad thing. So I set out along with my companion, sed, and together we squashed this beast.

PS1='$(A=$?; [ $A -ne 0 ] && A="!!{$A}!! " || A=""; SPWD=$(/bin/pwd | /usr/bin/sed -Ee "s,(/usr)?$HOME,~,; sz(/[^/]+/).*(/.{20,})$z\1...\2z"); /bin/echo -n $HOST"("$SPWD") [!] ${A}${Z} " )'

[ -w "/" ] && Z="#" || Z=">"; export Z
PROMPT='$(A=$?; [ $A -ne 0 ] && A="!!{$A}!! " || A=""; SPWD=$(/bin/pwd | \
/usr/bin/sed -Ee "s,(/usr)?$HOME,~,; sz(/[^/]+/).*(/.{20,})\$z\1...\2z"); \
/bin/echo -n $HOST"("$SPWD") [!] ${A}${Z} " )'

case $TERM in
   aterm|xterm|dtterm)
      PROMPT=${PROMPT%)*}'; /bin/echo -n "^[]2;"$HOST"("$SPWD") [!] ${A}^G" 1>&2)'
      ;;
esac
PS1=$PROMPT
The part marked in bold is what actually shortens the path. This will take what was previously a terribly long prompt and shorten the directory... ie;
/usr/local/lib/perl5/site_perl/5.6.1/Curses/UI/Dialog
will become
/usr/.../5.6.1/Curses/UI/Dialog

Oh, and this new feature actually makes the overal content of $PS1 shorter by 3 characters! Instead of 257 characters, it's 254. This is due to a rewrite of part of the code - pwd and sed are only called one time now.


4 responses to 'yes, even more ksh prompt fun...'

Showing last 4 comments... (Click here to view all comments)

Andrew Bond wrote at Fri Apr 20 15:14:28 2007...
$ . ./.profile
-ksh: .: syntax error: `)' unexpected

Jordan Sissel wrote at Fri Apr 20 20:15:59 2007...
Fixed for pdksh.

When I moved to the new blog tool (pyblosxom) from my old one (my own running in mysql) some things like funky strings weren't escaped properly.

Thanks for pointing it out. BTW, this won't work on Solaris' standard ksh (/bin/ksh) because it doesn't evaluate anything in $PS1 at prompt-time.

Kris wrote at Fri Aug 3 07:20:37 2007...
I understand the concept I'm just not sure how to put this in place.  Do I need to edit my .profile with this whole thing or just bits and pieces?

Cool blog by the way :)

Kris wrote at Fri Aug 3 07:34:11 2007...
I understand the concept I'm just not sure how to put this in place.  Do I need to edit my .profile with this whole thing or just bits and pieces?

Cool blog by the way :)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: