-
Notifications
You must be signed in to change notification settings - Fork 1
/
.ashrc
192 lines (176 loc) · 4.84 KB
/
.ashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# .ashrc - per-shell startup stuff for ash(1) and derivatives via $ENV
#
#ident "@(#)HOME:.ashrc 37.10 24/10/16 17:01:42 (woods)"
# Assumptions:
# - chdir must be synonymous with cd, and cd can be reset to a function
# Files referenced:
#
# $(dirname ${ENVFILE})/.shrc - sourced for common funcs, if needed & avail.
# ~${LOGNAME}/.shrc - sourced for common functs, if still needed
# $HOME/.shaliases - sourced, if it is readable
# $HOME/.ashedit - sourced, if it is readable else emacs editing set
# $HOME/.ashlocal - sourced, if it is readable, at the end
# $HOME/.ashpwd - sourced, if it is readable
# $HOME/.kshsccs - sourced, if "function" works and it is readable
# $HOME/.ashsccs - sourced, if it is readable and .kshsccs was not read
#echo "$0: in ~/.ashrc ...."
# try to find a related dotfiles, even when using "su" or a sub-shell the guts
#
# note: this code is duplicated in ~/.kshrc
#
if [ -n "${ENVFILE:-${ENV}}" ]; then
envhome=$(dirname ${ENVFILE:-${ENV}})
fi
# there's a bit of a chicken&egg situation w.r.t. LOGNAME (see ~/.shrc)
loghome=$(eval echo ~${LOGNAME})
if [ -n "${ENVFILE:-${ENV}}" -a -f ${envhome}/.shrc ]; then
HOME=${envhome}
elif [ -r ${loghome}/.shrc ]; then
HOME=${loghome}
fi
# else HOME stays unchanged...
unset envhome loghome
# Get basic shell setup from a .shrc
#
# It is assumed of course that "zhead" is defined as a function in the desired
# ~/.shrc file, and only there.
#
# note: this code is also duplicated in ~/.kshrc
#
if ! type zhead >/dev/null 2>&1; then
if [ -r ${HOME}/.shrc ]; then
. ${HOME}/.shrc
fi
fi
# ~/.shrc also does the tests for interactive/login shells and will also have
# returned "early" if neither (except if $FROM_DOT_PROFILE).
#
if ${sh_is_interactive} || ${sh_is_login}; then
: OK
else
# Everything else in this file is for interactive use only, but $ENV is
# set to just the plain filename of this file because ash(1) and its
# derivatives do not have arrays and so cannot use the ksh(1)
# ${ENVFILE[]} trick, so we must exit now.
#
return
fi
# xxx hmmm... how to tell other shells with this feature?
#
case $0 in
*dash*)
set -o emacs
;;
esac
# xxx hmmm... what about older versions? (prior to 2016-03-31 and netbsd-8)
if [ -n "${NETBSD_SHELL}" ]; then
set -o emacs
fi
# LEV counts (effectively) from zero, and is not set at level zero so as to
# avoid presenting redundant useless information using a simple ${LEV:+${LEV}}
# style of expansion.
#
# XXX in theory we could put this in ~/.shrc and it could even work for ancient
# Bourne shell provided the user did ". $ENV" and we made sure to set $PS1 with
# expanded values, but is it worth it?
#
if ${sh_is_login}; then
: this is a login shell
unset LEV
else
if [ ${PPID:-0} -eq 1 -o ${PPID:-1} -eq ${LAYERSPID:-0} ] ; then
: this is still considered a "login" shell
unset LEV
else
if [ -n "${LEV}" ] ; then
LEV=$((LEV+1))
else
LEV=1
fi
export LEV
fi
fi
# note this will be appended to.... (and variables must be quoted with single quotes)
if [ -n "${ToD}" ]; then
PS1='${ToD%:*}'
else
PS1='${UUNAME}'
fi
if ismpx -s || [ "$TERM" = "dmd-myx" ] ; then
unset -f cd
# NOTE: may be re-defined in ~/.ashpwd
cd ()
{
chdir ${1+"$@"}
# dumber than setban
BANNER_PWD=${PWD}
# faster than setban
eval myxban -l "\"$MYXBAN_L\""
}
fi
# else
case "$TERM" in
xterm*)
PS1="${PS1}"'${LEV:+[${LEV}]}'
unset -f cd
# NOTE: may be re-defined in ~/.ashpwd
cd ()
{
chdir ${1+"$@"}
BANNER_PWD=${PWD}
setban
}
;;
*)
# XXX these probably are not right to use ${BANNER_PWD} any more?
#
if [ "$user" != "$LOGNAME" ] ; then
PS1="${PS1}"'$TTYN:$user($LOGNAME)@$UUNAME)${LEV:+[${LEV}]} ${BANNER_PWD#$HOME}'
else
PS1="${PS1}"'$TTYN:$LOGNAME@$UUNAME[${LEV:+[${LEV}]} ${BANNER_PWD#$HOME}'
fi
;;
esac
PS1="${PS1} ${PSc} "
if type alias >/dev/null 2>&1 && [ -r $HOME/.shaliases ] ; then
. $HOME/.shaliases
fi
# finally we can clean up unnecessary functions
if type rm_alias_funcs >/dev/null 2>&1; then
rm_alias_funcs
fi
# xxx currently .kshsccs uses "function foo {}" syntax, and I've not discovered
# a way to use aliases or other funtions to translate that into "foo() {}"
# syntax.... Otherwise it would be compatible with BSD sh, Ash, dash, et al.
#
if type function >/dev/null 2>&1 && [ -r $HOME/.kshsccs ] ; then
. $HOME/.kshsccs
elif [ -r $HOME/.ashsccs ]; then
. $HOME/.ashsccs # xxx not yet translated... (maybe automatic, eval'ed?)
fi
if type setban >/dev/null 2>&1 && [ -r $HOME/.ashpwd ] ; then
. $HOME/.ashpwd
fi
lastcmd ()
{
tr '[\001-\007]' '[\012*]' < .sh_history | \
tr '[\176-\377]' '[ *]' | \
egrep -v '[ }#]|^$' | \
tail ${1+"$@"}
}
set -o monitor
# create an empty ~/.ashedit if your shell dies when you enable emacs
#
if [ -r $HOME/.ashedit ] ; then
. $HOME/.ashedit
else
case "$(set -o)" in
*emacs*)
set -o gmacs 2>/dev/null || set -o emacs
;;
esac
fi
if [ -r $HOME/.ashlocal ] ; then
. $HOME/.ashlocal
fi