photo
Jordan Sissel
geek

Mon, 18 Aug 2003

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.

Comments: 4 (view comments)
Tags:
Permalink: /geekery/60
posted at: 23:09


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

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

Jordan Sissel posted at Fri Apr 20 23: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 posted at Fri Aug 3 10: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 posted at Fri Aug 3 10: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:


Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< August 2003 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
31      

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati