1da2e3ebdSchin# 2da2e3ebdSchin# CDDL HEADER START 3da2e3ebdSchin# 4da2e3ebdSchin# The contents of this file are subject to the terms of the 5da2e3ebdSchin# Common Development and Distribution License (the "License"). 6da2e3ebdSchin# You may not use this file except in compliance with the License. 7da2e3ebdSchin# 8da2e3ebdSchin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9da2e3ebdSchin# or http://www.opensolaris.org/os/licensing. 10da2e3ebdSchin# See the License for the specific language governing permissions 11da2e3ebdSchin# and limitations under the License. 12da2e3ebdSchin# 13da2e3ebdSchin# When distributing Covered Code, include this CDDL HEADER in each 14da2e3ebdSchin# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15da2e3ebdSchin# If applicable, add the following below this CDDL HEADER, with the 16da2e3ebdSchin# fields enclosed by brackets "[]" replaced with your own identifying 17da2e3ebdSchin# information: Portions Copyright [yyyy] [name of copyright owner] 18da2e3ebdSchin# 19da2e3ebdSchin# CDDL HEADER END 20da2e3ebdSchin# 21da2e3ebdSchin 22da2e3ebdSchin# 23*34f9b3eeSRoland Mainz# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24da2e3ebdSchin# Use is subject to license terms. 25da2e3ebdSchin# 26da2e3ebdSchin 27da2e3ebdSchin# 28da2e3ebdSchin# This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc 29da2e3ebdSchin# 30da2e3ebdSchin 317c2fbfb3SApril Chin# Enable "gmacs"+"multiline" editor mode if the user did not set an 327c2fbfb3SApril Chin# input mode yet (for example via ${EDITOR}, ${VISUAL} or any 337c2fbfb3SApril Chin# "set -o" flag) 347c2fbfb3SApril Chinif [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then 35da2e3ebdSchin set -o gmacs 367c2fbfb3SApril Chin # enable multiline input mode 377c2fbfb3SApril Chin set -o multiline 38*34f9b3eeSRoland Mainz # enable globstar mode (match subdirs with **/) 39*34f9b3eeSRoland Mainz set -o globstar 40da2e3ebdSchinfi 41da2e3ebdSchin 427c2fbfb3SApril Chin# Set a default prompt (<username>@<hostname>:<path><"($|#) ">) if 437c2fbfb3SApril Chin# then variable does not exist in the environment. 447c2fbfb3SApril Chin# 457c2fbfb3SApril Chin# Algorithm: 467c2fbfb3SApril Chin# 1. Define "ellipsis", either Unicode #2026 for unicode locales 477c2fbfb3SApril Chin# and "..." otherwise 487c2fbfb3SApril Chin# ([[ "${LC_ALL}/${LANG}" = ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] 497c2fbfb3SApril Chin# ensures that the pattern matches the leftmost sequence 507c2fbfb3SApril Chin# containing *.UTF-8, allowing to match either LC_ALL or 517c2fbfb3SApril Chin# LANG when LC_ALL is not set) 527c2fbfb3SApril Chin# 2. If PWD is within HOME replace value of HOME with '~' 537c2fbfb3SApril Chin# If the PWD is longer than 30 charatcers shorten it to 30 chars 547c2fbfb3SApril Chin# print '#' for user "root" and '$' for normal users 557c2fbfb3SApril Chin# Notes: 567c2fbfb3SApril Chin# - printf "%*s\r%s" COLUMNS "") # is used at the beginning to 577c2fbfb3SApril Chin# work around a bug in the "multiline" handling code which 587c2fbfb3SApril Chin# causes the shell to override its own prompt when the edit 597c2fbfb3SApril Chin# line overflows (this happens if the terminal cursor 607c2fbfb3SApril Chin# position is not 0 when PS1 is printed). 617c2fbfb3SApril Chin# - PS1 will initially be empty until either... 627c2fbfb3SApril Chin# a) ... someone sets the variable 637c2fbfb3SApril Chin# or 647c2fbfb3SApril Chin# b) ... the prompt is displayed for the first time (default is 657c2fbfb3SApril Chin# '$ ' for normal users and '# ' for user "root") 667c2fbfb3SApril Chin# - The statement below will not work if someone sources /etc/ksh.kshrc 677c2fbfb3SApril Chin# unless PS1 gets "unset" first. 687c2fbfb3SApril Chin# - Make sure to use absolute paths (e.g. /usr/bin/hostname) to make 697c2fbfb3SApril Chin# sure PS1 works in cases where PATH does not contain /usr/bin/ 707c2fbfb3SApril Chinif [[ "$(set)" != ~(E)PS1= && "${PS1}" == '' ]] ; then 71*34f9b3eeSRoland Mainz PS1='$(set +o xtrace +o errexit 72*34f9b3eeSRoland Mainz printf "%*s\r%s" COLUMNS "" 73*34f9b3eeSRoland Mainz printf "%s@%s:" "${LOGNAME}" "$(/usr/bin/hostname)" 74*34f9b3eeSRoland Mainz ellip="${ 757c2fbfb3SApril Chin [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] && 76*34f9b3eeSRoland Mainz printf "\u[2026]\n" || print "..." ; }" 777c2fbfb3SApril Chin p="${PWD/~(El)${HOME}/\~}" 787c2fbfb3SApril Chin (( ${#p} > 30 )) && 797c2fbfb3SApril Chin print -r -n -- "${ellip}${p:${#p}-30:30}" || 807c2fbfb3SApril Chin print -r -n -- "${p}" 817c2fbfb3SApril Chin [[ "${LOGNAME}" == "root" ]] && print -n "# " || print -n "\$ " 827c2fbfb3SApril Chin )' 837c2fbfb3SApril Chinfi 84