photo
Jordan Sissel
geek

Fri, 01 Aug 2003

Neat ksh prompt

My prompt is something in the form of:
hostname(/path/to/pwd) [###] >

Unless the previous command that was executed returned an exit code other than 0, in which case it will display the exit code just before the > as !#! where # is the exit code.

from my .profile

[ -w "/" ] && Z="#" || Z=">"
EXITCODE='$(A=$? && [ $A -ne 0 ] && echo "!!${A}!! ")'
PS1='$HOST($(/bin/pwd | sed -Ee "s,(/usr)?$HOME,~,")) [!] '$EXITCODE'$Z '

This will let you use pwd and substitute ~ for your home directory. (pdksh currently doesn't support something like this, so the hack was needed)

That's it, here's an example of what it'll look like:

nightfall(~) [471] > 
nightfall(~) [471] > echo "hi there"
hi there
nightfall(~) [472] > ls -asoijo23i5j23
ls: illegal option -- j
usage: ls [-ABCFGHLPRTWabcdfghiklnoqrstu1] [file ...]
nightfall(~) [473] !1! > thisisnotacommand
ksh: thisisnotacommand: not found
nightfall(~) [474] !127! > cd bin
nightfall(~/bin) [475] > cd /nope
ksh: cd: /nope - No such file or directory
nightfall(~/bin) [476] !1! > cd /usr/local/
nightfall(/usr/local) [477] > 

Note the !1! and !127!. These are the exit codes of the previous commands.

Comments: 0 (view comments)
Tags:
Permalink: /geekery/35
posted at: 03:34

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 '08 Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials SSH Tunneling (Video)

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