Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 May 1998 12:17:18 -0400
From:      Gary Algier <gaa@dgms.com>
To:        freebsd-questions@FreeBSD.ORG, matt@zigg.com
Subject:   Re: parsable promptstring in sh?
Message-ID:  <3553300E.8072A332@dgms.com>
References:  <Pine.BSF.3.96.980507142109.25649A-100000@megaweapon.zigg.com>

next in thread | previous in thread | raw e-mail | index | archive | help
owner-freebsd-questions@FreeBSD.ORG wrote:
> 
> Can I somehow do this:
> 
>         set -o promptexpn
>         PS1=\`pwd\`$; export PS1
> 
> or some such to have a prompt that is expanded by sh?  (I know there is no
> promptexpn option, per se, but there's got to be something, right?)
> 
>   Matt Behrens <matt@zigg.com>   | From an actual Linux machine, in
>   http://www.zigg.com/           |  production use:
>   Chanop Script Coordinator      | <censored>$ w
>   World-Wide FreeNet IRC Network | Segmentation fault
> 
I use ksh (in the ports collection is shells/pdksh) and I use:
--------------------------------------------------------------------
# simple prompt:
export PS1="${USER:-${LOGNAME}}@${HOSTNAME%%.*} !% "

# complex "prompt":
if [[ -t 1 && $TERM = *xterm* ]]
then
        # this will place:
        #     the full path, less the home directory in the title bar
        #     the last dir part in the icon name
        #     the user@hostname and sequence in the prompt
        # the \$ sequences here are for defered expansion
        bell=$(print -n "\007")
        cr=$(print -n "\015")
        esc=$(print -n "\033")
        PS1="$esc]2; \${PWD#$HOME/}$bell"
        PS1="$PS1$esc]1; \${PWD##*/}$bell"
        PS1="$PS1$cr${USER:-${LOGNAME}}@${HOSTNAME%%.*} !% "
        unset bell cr esc
fi
--------------------------------------------------------------------
Notes:
The $cr is used because the shell otherwise miscalculates the space left to
the right of the prompt and will not show much at all.

I put the path in the window title to keep it out of the way of my typing.
I don't know how people can use a prompt that is 40 characters or
more long (yes, I have even seen where someone was so deep down that
the prompt wrapped!)

Also, with ksh you get good command line editting:
	set -o vi	# for vi style
	set -o emacs	# for emacs style
And much better shell functions, local variables, integer data types, etc.

-- 
Gary Algier, WB2FWZ       gary.algier@dgms.com              +1 609 608 2758
DGM&S Telecom, 1025 Briggs Rd, Mt. Laurel, NJ 08054     Fax:+1 609 866 8850
        Paul Petzoldt on the renaming of Mount Washington:
"I Call it the New England Booby Trap.  We see Ph.D.'s from private schools
taking kids up there in shorts.  People die like flies up there!"

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3553300E.8072A332>