Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/data/bash_pre_rc.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
#
21
# bash compatibility startup script
22
#
23
# Author:
24
# Karsten Fleischer
25
# Omnium Software Engineering
26
# An der Luisenburg 7
27
# D-51379 Leverkusen
28
# Germany
29
#
30
# <[email protected]>
31
#
32
33
alias declare=typeset
34
35
nameref FUNCNAME=.sh.fun
36
integer SHLVL
37
export SHLVL
38
SHLVL+=1
39
40
if [[ ! $EUID ]]
41
then EUID=$(id -u)
42
readonly EUID
43
fi
44
45
if [[ ! $UID ]]
46
then UID=$(id -u)
47
readonly UID
48
fi
49
50
readonly SHELLOPTS
51
if ! shopt -qo restricted; then
52
IFS=:
53
for i in $SHELLOPTS
54
do
55
[[ -n "$i" ]] && set -o $i
56
done
57
unset IFS
58
fi
59
function SHELLOPTS.get
60
{
61
.sh.value=$(shopt -so)
62
.sh.value=${.sh.value//+([[:space:]])on*([[:space:]])/:}
63
.sh.value=${.sh.value%:}
64
}
65
66
set -A GROUPS $(id -G)
67
function GROUPS.set
68
{
69
return 1
70
}
71
function GROUPS.unset
72
{
73
unset -f GROUPS.set
74
unset -f GROUPS.unset
75
}
76
77
typeset -A DIRSTACK
78
function DIRSTACK.get
79
{
80
set -A .sh.value $(dirs)
81
}
82
function DIRSTACK.set
83
{
84
integer index
85
index=_push_max-.sh.subscript
86
(( index == _push_max || index < _push_top )) && return
87
_push_stack[index]=${.sh.value}
88
}
89
function DIRSTACK.unset
90
{
91
unset -f DIRSTACK.get
92
unset -f DIRSTACK.set
93
unset -f DIRSTACK.unset
94
}
95
96
function PS1.set
97
{
98
typeset prefix remaining=${.sh.value} var= n= k=
99
while [[ $remaining ]]
100
do prefix=${remaining%%'\'*}
101
remaining=${remaining#$prefix}
102
var+="$prefix"
103
case ${remaining:1:1} in
104
t) var+="\$(printf '%(%H:%M:%S)T')";;
105
d) var+="\$(printf '%(%a %b:%e)T')";;
106
n) var+=$'\n';;
107
s) var+=ksh;;
108
w) var+="\$(pwd)";;
109
W) var+="\$(basename \"\$(pwd)\")";;
110
u) var+=$USER;;
111
h) var+=$(hostname -s);;
112
'#') var+=!;;
113
!) var+=!;;
114
@) var+="\$(printf '%(%I:%M%p)T')";;
115
'$') if (( $(id -u) == 0 ))
116
then var+='#'
117
else var+='$'
118
fi;;
119
'\') var+='\\';;
120
'['|']') ;;
121
[0-7]) case ${remaining:1:3} in
122
[0-7][0-7][0-7])
123
k=4;;
124
[0-7][0-7])
125
k=3;;
126
*) k=2;;
127
esac
128
eval n="\$'"${remaining:0:k}"'"
129
var+=$n
130
remaining=${remaining:k}
131
continue
132
;;
133
"") ;;
134
*) var+='\'${remaining:0:2};;
135
esac
136
remaining=${remaining:2}
137
done
138
.sh.value=$var
139
}
140
function logout
141
{
142
if shopt -q login_shell; then
143
exit
144
else
145
print ${BASH##*/}: $0: not login shell: use 'exit' >&2
146
return 1
147
fi
148
}
149
PS1="bash$ "
150
151
function source
152
{
153
if ! shopt -qpo posix; then
154
unset OPATH
155
typeset OPATH=$PATH
156
typeset PATH=$PATH
157
if shopt -q sourcepath; then
158
PATH=$OPATH:.
159
else
160
PATH=.
161
fi
162
fi
163
. "$@"
164
}
165
unalias .
166
alias .=source
167
168
alias enable=builtin
169
170
function help
171
{
172
typeset b cmd usage try_cmd man
173
function has_help_option
174
{
175
[[ $1 == @(''|/*|:|echo|false|true|login|test|'[') ]] && return 1
176
return 0
177
}
178
typeset -A short_use=(
179
[echo]='Usage: echo [ options ] [arg]...'
180
[:]='Usage: : ...'
181
[true]='Usage: true ...'
182
[false]='Usage: false ...'
183
[login]='Usage: login [-p] [name]'
184
['[']='Usage: [ EXPRESSION ] | [ OPTION'
185
[test]='Usage: test EXPRESSION | test'
186
)
187
b=$(builtin)
188
if (( $# == 0))
189
then print 'The following is the current list of built-in commands:'
190
print -r $'Type help *name* for more information about name\n'
191
for cmd in $b
192
do if has_help_option $cmd
193
then usage=$($cmd --short 2>&1)
194
print -r -- "${usage:7}"
195
else print -r -- ${short_use[$cmd]:7}
196
fi
197
done
198
return
199
fi
200
b=${b/'['/}
201
man=--man
202
[[ $1 == -s ]] && man=--short && shift
203
for try_cmd
204
do if has_help_option $try_cmd
205
then if [[ $try_cmd == @(${b//$'\n'/'|'}) ]]
206
then $try_cmd $man
207
else man $try_cmd
208
fi
209
elif [[ $man == '--short' ]]
210
then print -r -- ${short_use[$try_cmd]}
211
else man $try_cmd
212
fi
213
done
214
}
215
216
function cd
217
{
218
219
local msg
220
local args
221
local i
222
local a
223
local ret
224
225
if ! shopt -q cdable_vars; then
226
command cd "$@"
227
else
228
msg=$(command cd "$@" 2>&1)
229
ret=$?
230
if [[ $ret != 0 ]]; then
231
for i
232
do
233
case $i in
234
-*) args="$args $i" ;;
235
*/*) args="$args $i" ;;
236
*) eval a="$"$i
237
if [[ -n $a ]]; then args="$args $a"
238
else args="$args $i"
239
fi
240
;;
241
esac
242
done
243
244
command cd $args
245
else
246
print -- $msg
247
return $ret
248
fi
249
fi
250
}
251
252
typeset BASH=$0
253
! shopt -qo posix && HISTFILE=~/.bash_history
254
HOSTNAME=$(hostname)
255
nameref BASH_SUBSHELL=.sh.subshell
256
257