ksh.kshrc (da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968) ksh.kshrc (7c2fbfb345896881c631598ee3852ce9ce33fb07)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24# Use is subject to license terms.
25#
24# Use is subject to license terms.
25#
26# ident "%Z%%M% %I% %E% SMI"
27#
28
29#
30# This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc
31#
32
26
27#
28# This file is sourced by interactive ksh93 shells before ${HOME}/.kshrc
29#
30
33# Enable "gmacs" editor mode if the user did not set an input mode yet
34# (for example via ${EDITOR}, ${VISUAL} or any "set -o" flag)
35if [[ "$(set +o)" != ~(E)--(gmacs|emacs|vi)( |$) ]] ; then
36 set -o gmacs
31# Enable "gmacs"+"multiline" editor mode if the user did not set an
32# input mode yet (for example via ${EDITOR}, ${VISUAL} or any
33# "set -o" flag)
34if [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then
35 set -o gmacs
36 # enable multiline input mode
37 set -o multiline
37fi
38
38fi
39
39
40# enable multiline input mode
41#set -o multiline
42
40# Set a default prompt (<username>@<hostname>:<path><"($|#) ">) if
41# then variable does not exist in the environment.
42#
43# Algorithm:
44# 1. Define "ellipsis", either Unicode #2026 for unicode locales
45# and "..." otherwise
46# ([[ "${LC_ALL}/${LANG}" = ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]]
47# ensures that the pattern matches the leftmost sequence
48# containing *.UTF-8, allowing to match either LC_ALL or
49# LANG when LC_ALL is not set)
50# 2. If PWD is within HOME replace value of HOME with '~'
51# If the PWD is longer than 30 charatcers shorten it to 30 chars
52# print '#' for user "root" and '$' for normal users
53# Notes:
54# - printf "%*s\r%s" COLUMNS "") # is used at the beginning to
55# work around a bug in the "multiline" handling code which
56# causes the shell to override its own prompt when the edit
57# line overflows (this happens if the terminal cursor
58# position is not 0 when PS1 is printed).
59# - PS1 will initially be empty until either...
60# a) ... someone sets the variable
61# or
62# b) ... the prompt is displayed for the first time (default is
63# '$ ' for normal users and '# ' for user "root")
64# - The statement below will not work if someone sources /etc/ksh.kshrc
65# unless PS1 gets "unset" first.
66# - Make sure to use absolute paths (e.g. /usr/bin/hostname) to make
67# sure PS1 works in cases where PATH does not contain /usr/bin/
68if [[ "$(set)" != ~(E)PS1= && "${PS1}" == '' ]] ; then
69 PS1='$(printf "%*s\r%s" COLUMNS "")${LOGNAME}@$(/usr/bin/hostname):$(
70 ellip="$(
71 [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] &&
72 printf "\u[2026]\n" || print "..." )"
73 p="${PWD/~(El)${HOME}/\~}"
74 (( ${#p} > 30 )) &&
75 print -r -n -- "${ellip}${p:${#p}-30:30}" ||
76 print -r -n -- "${p}"
77 [[ "${LOGNAME}" == "root" ]] && print -n "# " || print -n "\$ "
78 )'
79fi