-
Notifications
You must be signed in to change notification settings - Fork 1
/
.ashpwd
92 lines (89 loc) · 2.24 KB
/
.ashpwd
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
#
# .ashpwd - local stuff to abbreviate PWD...
#
#ident "@(#)HOME:.ashpwd 37.2 22/02/23 17:23:12 (woods)"
# This works entirely with global variables -- handling parameters is just more
# unnecessary overhead for this purpose
#
# This version still uses ${name#pattern} substitution, but of course cannot use
# the extra Ksh filename globbing patterns.
#
pwd_to_banner()
{
#
# NOTE: some derivatives of ash(1) will always set $PWD to be
# the directory returned by getcwd(3), and not the symlink(s)
# given to chdir and followed to get to the current directory,
# so some of these abbreviations may not always have the
# desired effect, based on the configuration of the local
# system.
#
case "$PWD" in
${HOME})
# avoid the trailing slash, e.g.: sh://host/~/
BANNER_PWD='~'
;;
${HOME}/*)
BANNER_PWD='~'${PWD#$HOME}
;;
$(dirname ${HOME})/*)
BANNER_PWD='~'"${PWD#$(dirname $HOME)/}"
;;
/home/*)
BANNER_PWD='~'"${PWD#/home/}"
;;
*/work/${LOGNAME}/*)
BANNER_PWD='mywork:'"${PWD#*/work/${LOGNAME}/}"
;;
*/work.d/${LOGNAME}/*)
BANNER_PWD='mywork:'"${PWD#*/work.d/${LOGNAME}/}"
;;
*/work/*)
BANNER_PWD='work:'"${PWD#*/work/}"
;;
*/work.d/*)
BANNER_PWD='work:'"${PWD#*/work.d/}"
;;
/usr/src/*)
BANNER_PWD='src:'"${PWD#/usr/src/}"
;;
/usr/pkgsrc/*)
BANNER_PWD='pkgsrc:'"${PWD#/usr/pkgsrc/}"
;;
/usr/xsrc/*)
BANNER_PWD='xsrc:'"${PWD#/usr/xsrc/}"
;;
*)
# trim just the leading slash to avoid "sh://host//dir"
BANNER_PWD="${PWD#/}"
;;
esac
}
# NOTE: the only real difference between this and .kshpwd is that this
# version only defines a function which hides the builtin (no alias)
# and it then uses the alternate builtin of "chdir". The content of
# the inner "case" statement should be identical.
#
unset -f cd
cd ()
{
# XXX could supposedly also use: command cd "$*"
# XXX but it ("command") may not be in all versions....
# XXX and it seems to be broken in at least FreeBSD-8
chdir ${1+"$@"}
pwd_to_banner
if [ "$(ismpx)" = yes ] ; then
eval myxban -l "\"$MYXBAN_L\""
# there would be no point without setban, but we must test it anyway
elif type setban > /dev/null ; then
setban
fi
}
# make sure BANNER_PWD is now set as we want it,
# but _ONLY_ for interactive shells!
#
case "$0" in
-*)
cd .
;;
esac