NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/16226 (Prompt expansion for /bin/sh)

Synopsis: Prompt expansion for /bin/sh

State-Changed-From-To: open->feedback
State-Changed-When: Sat, 01 Jul 2017 00:05:27 +0000
It has been a mere 15 years (and a few months), but /bin/sh (in NetBSD current)
now has PS1 (and PS2, PS4) variable expansion (and a few ner variables to
assist with building prompts).

To get the hostname, use ${HOSTNAME} (for whatever gethostname(3) returns)
or ${HOSTNAME%%.*} for the short form.

For the current directory use ${PWD}, or ${PWD##*/} for only the last
component.   For smarter expansions, wrap a function around the cd
command, something like

		command cd "$@" || return

		case "${PDIR}/" in
		"${HOME}/")	PDIR='~'"${PDIR#${HOME}}" ;;

		# and any other modifications you want

and then use $PDIR (any name you like) in PS1 (or elsewhere).

For the $/# expansion, use $PSc

Set PS1 with a '' string to avoid expanding the values at definition time.

See sh(1) (from NetBSD current, and maybe NetBSD 8 before it gets released)
for more information on what can be done.

Hopefully this is enough to satisfy the request in this PR.

Home | Main Index | Thread Index | Old Index