• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# $Id$
2# $MirOS: src/bin/mksh/dot.mkshrc,v 1.128 2020/04/13 18:39:03 tg Exp $
3#-
4# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
5#		2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
6#		2020
7#	mirabilos <m@mirbsd.org>
8#
9# Provided that these terms and disclaimer and all copyright notices
10# are retained or reproduced in an accompanying document, permission
11# is granted to deal in this work without restriction, including un-
12# limited rights to use, publicly perform, distribute, sell, modify,
13# merge, give away, or sublicence.
14#
15# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
16# the utmost extent permitted by applicable law, neither express nor
17# implied; without malicious intent or gross negligence. In no event
18# may a licensor, author or contributor be held liable for indirect,
19# direct, other damage, loss, or other issues arising in any way out
20# of dealing in the work, even if advised of the possibility of such
21# damage or existence of a defect, except proven that it results out
22# of said person's immediate fault when using the work as intended.
23#-
24# ${ENV:-~/.mkshrc}: mksh initialisation file for interactive shells
25
26# catch non-mksh, non-lksh, trying to run this file
27case ${KSH_VERSION:-} in
28*LEGACY\ KSH*|*MIRBSD\ KSH*) ;;
29*) \return 0 ;;
30esac
31
32# give MidnightBSD's laffer1 a bit of csh feeling
33function setenv {
34	if (( $# )); then
35		\\builtin eval '\\builtin export "$1"="${2:-}"'
36	else
37		\\builtin typeset -x
38	fi
39}
40
41# pager (not control character safe)
42smores() (
43	\\builtin set +m
44	\\builtin cat "$@" |&
45	\\builtin trap "rv=\$?; \\\\builtin kill $! >/dev/null 2>&1; \\\\builtin exit \$rv" EXIT
46	while IFS= \\builtin read -pr line; do
47		llen=${%line}
48		(( llen == -1 )) && llen=${#line}
49		(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
50		if (( (curlin += llen) >= LINES )); then
51			\\builtin print -nr -- $'\e[7m--more--\e[0m'
52			\\builtin read -u1 || \\builtin exit $?
53			[[ $REPLY = [Qq]* ]] && \\builtin exit 0
54			curlin=$llen
55		fi
56		\\builtin print -r -- "$line"
57	done
58)
59
60# customise your favourite editor here; the first one found is used
61for EDITOR in "${EDITOR:-}" jupp jstar mcedit ed vi; do
62	EDITOR=$(\\builtin whence -p "$EDITOR") || EDITOR=
63	[[ -n $EDITOR && -x $EDITOR ]] && break
64	EDITOR=
65done
66
67\\builtin alias ls=ls l='ls -F' la='l -a' ll='l -l' lo='l -alo'
68\: "${EDITOR:=/bin/ed}${TERM:=vt100}${USER:=$(\\builtin ulimit -c 0; id -un \
69    2>/dev/null)}${HOSTNAME:=$(\\builtin ulimit -c 0; hostname 2>/dev/null)}"
70[[ $HOSTNAME = ?(?(ip6-)localhost?(6)) ]] && HOSTNAME=nil; \\builtin unalias ls
71\\builtin export EDITOR HOSTNAME TERM USER="${USER:-?}"
72
73# minimal support for lksh users
74if [[ $KSH_VERSION = *LEGACY\ KSH* ]]; then
75	PS1='$USER@${HOSTNAME%%.*}:$PWD>'
76	\\builtin return 0
77fi
78
79# mksh-specific from here
80\: "${MKSH:=$(\\builtin whence -p mksh)}${MKSH:=/bin/mksh}"
81\\builtin export MKSH
82
83# prompts
84PS4='[$EPOCHREALTIME] '; PS1='#'; (( USER_ID )) && PS1='$'; PS1=$'\001\r''${|
85	\\builtin typeset e=$?
86
87	(( e )) && REPLY+="$e|"
88	REPLY+=${USER}@${HOSTNAME%%.*}:
89
90	\\builtin typeset d=${PWD:-?}/ p=~; [[ $p = ?(*/) ]] || d=${d/#$p\//\~/}
91	d=${d%/}; \\builtin typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
92	(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p=
93	REPLY+=$p$d
94
95	\\builtin return $e
96} '"$PS1 "
97
98# utilities
99\\builtin alias doch='sudo mksh -c "$(\\builtin fc -ln -1)"'
100\\builtin command -v rot13 >/dev/null || \\builtin alias rot13='tr \
101    abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \
102    nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
103if \\builtin command -v hd >/dev/null; then
104	\:
105elif \\builtin command -v hexdump >/dev/null; then
106	function hd {
107		hexdump -e '"%08.8_ax  " 8/1 "%02X " " - " 8/1 "%02X "' \
108		    -e '"  |" "%_p"' -e '"|\n"' "$@"
109	}
110else
111	function hd {
112		\\builtin cat "$@" | hd_mksh
113	}
114fi
115
116# NUL-safe and EBCDIC-safe hexdump (from stdin)
117function hd_mksh {
118	\\builtin typeset -Uui16 -Z11 pos=0
119	\\builtin typeset -Uui16 -Z5 hv=2147483647
120	\\builtin typeset dasc dn line i
121	\\builtin set +U
122
123	while \\builtin read -arn 512 line; do
124		\\builtin typeset -i1 'line[*]'
125		i=0
126		while (( i < ${#line[*]} )); do
127			dn=
128			(( (hv = line[i++]) != 0 )) && dn=${line[i-1]#1#}
129			if (( (pos & 15) == 0 )); then
130				(( pos )) && \
131				    \\builtin print -r -- "$dasc|"
132				\\builtin print -nr "${pos#16#}  "
133				dasc=' |'
134			fi
135			\\builtin print -nr "${hv#16#} "
136			if [[ $dn = [[:print:]] ]]; then
137				dasc+=$dn
138			else
139				dasc+=.
140			fi
141			(( (pos++ & 15) == 7 )) && \
142			    \\builtin print -nr -- '- '
143		done
144	done
145	while (( pos & 15 )); do
146		\\builtin print -nr '   '
147		(( (pos++ & 15) == 7 )) && \
148		    \\builtin print -nr -- '- '
149	done
150	(( hv == 2147483647 )) || \\builtin print -r -- "$dasc|"
151}
152
153function which {
154	\\builtin typeset p x c
155	\\builtin typeset -i a=0 rv=2 e
156	\\builtin set +e
157	\\builtin set -o noglob
158
159	while \\builtin getopts "a" x; do
160		case $x {
161		(a)	a=1 ;;
162		(+a)	a=0 ;;
163		(*)	\\builtin print -ru2 'Usage: which [-a] name [...]'
164			\\builtin return 255 ;;
165		}
166	done
167	\\builtin shift $((OPTIND - 1))
168
169	#        vvvvvvvvvvvvvvvvvvvv should be def_path
170	p=${PATH-/usr/bin$PATHSEP/bin}
171	#       ^ no colon!
172
173	# trailing PATHSEP vs field splitting
174	[[ $p = *"$PATHSEP" ]] && p+=.
175
176	IFS=$PATHSEP
177	\\builtin set -A p -- ${p:-.}
178	IFS=$' \t\n'
179
180	for x in "$@"; do
181		if (( !a )) || [[ $x = */* ]]; then
182			\\builtin whence -p -- "$x"
183			e=$?
184		else
185			e=1
186			for c in "${p[@]}"; do
187				PATH=${c:-.} \\builtin whence -p -- "$x" && e=0
188			done
189		fi
190		(( rv = (e == 0) ? (rv & ~2) : (rv == 2 ? 2 : 1) ))
191	done
192	\\builtin return $rv
193}
194
195# Berkeley C shell compatible dirs, popd, and pushd functions
196# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
197DIRSTACKBASE=$(\\builtin realpath ~/. 2>/dev/null || \
198    \\builtin print -nr -- "${HOME:-/}")
199\\builtin set -A DIRSTACK
200function chpwd {
201	DIRSTACK[0]=$(\\builtin realpath . 2>/dev/null || \
202	    \\builtin print -nr -- "$PWD")
203	[[ $DIRSTACKBASE = ?(*/) ]] || \
204	    DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/\~}
205	\:
206}
207\chpwd .
208cd() {
209	\\builtin cd "$@" || \\builtin return $?
210	\chpwd "$@"
211}
212function cd_csh {
213	\\builtin typeset d t=${1/#\~/$DIRSTACKBASE}
214
215	if ! d=$(\\builtin cd "$t" 2>&1); then
216		\\builtin print -ru2 "${1}: ${d##*cd: $t: }."
217		\\builtin return 1
218	fi
219	\cd "$t"
220}
221function dirs {
222	\\builtin typeset d dwidth
223	\\builtin typeset -i fl=0 fv=0 fn=0 cpos=0
224
225	while \\builtin getopts ":lvn" d; do
226		case $d {
227		(l)	fl=1 ;;
228		(v)	fv=1 ;;
229		(n)	fn=1 ;;
230		(*)	\\builtin print -ru2 'Usage: dirs [-lvn].'
231			\\builtin return 1 ;;
232		}
233	done
234	\\builtin shift $((OPTIND - 1))
235	if (( $# > 0 )); then
236		\\builtin print -ru2 'Usage: dirs [-lvn].'
237		\\builtin return 1
238	fi
239	if (( fv )); then
240		fv=0
241		while (( fv < ${#DIRSTACK[*]} )); do
242			d=${DIRSTACK[fv]}
243			(( fl )) && d=${d/#\~/$DIRSTACKBASE}
244			\\builtin print -r -- "$fv	$d"
245			(( ++fv ))
246		done
247	else
248		fv=0
249		while (( fv < ${#DIRSTACK[*]} )); do
250			d=${DIRSTACK[fv]}
251			(( fl )) && d=${d/#\~/$DIRSTACKBASE}
252			(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) ))
253			if (( fn && (cpos += dwidth + 1) >= 79 && \
254			    dwidth < 80 )); then
255				\\builtin print
256				(( cpos = dwidth + 1 ))
257			fi
258			\\builtin print -nr -- "$d "
259			(( ++fv ))
260		done
261		\\builtin print
262	fi
263	\\builtin return 0
264}
265function popd {
266	\\builtin typeset d fa
267	\\builtin typeset -i n=1
268
269	while \\builtin getopts ":0123456789lvn" d; do
270		case $d {
271		(l|v|n)	fa+=" -$d" ;;
272		(+*)	n=2
273			\\builtin break ;;
274		(*)	\\builtin print -ru2 'Usage: popd [-lvn] [+<n>].'
275			\\builtin return 1 ;;
276		}
277	done
278	\\builtin shift $((OPTIND - n))
279	n=0
280	if (( $# > 1 )); then
281		\\builtin print -ru2 popd: Too many arguments.
282		\\builtin return 1
283	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
284		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
285			\\builtin print -ru2 popd: Directory stack not that deep.
286			\\builtin return 1
287		fi
288	elif [[ -n $1 ]]; then
289		\\builtin print -ru2 popd: Bad directory.
290		\\builtin return 1
291	fi
292	if (( ${#DIRSTACK[*]} < 2 )); then
293		\\builtin print -ru2 popd: Directory stack empty.
294		\\builtin return 1
295	fi
296	\\builtin unset DIRSTACK[n]
297	\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}"
298	\cd_csh "${DIRSTACK[0]}" || \\builtin return 1
299	\dirs $fa
300}
301function pushd {
302	\\builtin typeset d fa
303	\\builtin typeset -i n=1
304
305	while \\builtin getopts ":0123456789lvn" d; do
306		case $d {
307		(l|v|n)	fa+=" -$d" ;;
308		(+*)	n=2
309			\\builtin break ;;
310		(*)	\\builtin print -ru2 'Usage: pushd [-lvn] [<dir>|+<n>].'
311			\\builtin return 1 ;;
312		}
313	done
314	\\builtin shift $((OPTIND - n))
315	if (( $# == 0 )); then
316		if (( ${#DIRSTACK[*]} < 2 )); then
317			\\builtin print -ru2 pushd: No other directory.
318			\\builtin return 1
319		fi
320		d=${DIRSTACK[1]}
321		DIRSTACK[1]=${DIRSTACK[0]}
322		\cd_csh "$d" || \\builtin return 1
323	elif (( $# > 1 )); then
324		\\builtin print -ru2 pushd: Too many arguments.
325		\\builtin return 1
326	elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
327		if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
328			\\builtin print -ru2 pushd: Directory stack not that deep.
329			\\builtin return 1
330		fi
331		while (( n-- )); do
332			d=${DIRSTACK[0]}
333			\\builtin unset DIRSTACK[0]
334			\\builtin set -A DIRSTACK -- "${DIRSTACK[@]}" "$d"
335		done
336		\cd_csh "${DIRSTACK[0]}" || \\builtin return 1
337	else
338		\\builtin set -A DIRSTACK -- placeholder "${DIRSTACK[@]}"
339		\cd_csh "$1" || \\builtin return 1
340	fi
341	\dirs $fa
342}
343
344# base64 encoder and decoder, RFC compliant, NUL safe, not EBCDIC safe
345function Lb64decode {
346	\\builtin set +U
347	\\builtin typeset c s="$*" t
348	[[ -n $s ]] || { s=$(\\builtin cat; \\builtin print x); s=${s%x}; }
349	\\builtin typeset -i i=0 j=0 n=${#s} p=0 v x
350	\\builtin typeset -i16 o
351
352	while (( i < n )); do
353		c=${s:(i++):1}
354		case $c {
355		(=)	\\builtin break ;;
356		([A-Z])	(( v = 1#$c - 65 )) ;;
357		([a-z])	(( v = 1#$c - 71 )) ;;
358		([0-9])	(( v = 1#$c + 4 )) ;;
359		(+)	v=62 ;;
360		(/)	v=63 ;;
361		(*)	\\builtin continue ;;
362		}
363		(( x = (x << 6) | v ))
364		case $((p++)) {
365		(0)	\\builtin continue ;;
366		(1)	(( o = (x >> 4) & 255 )) ;;
367		(2)	(( o = (x >> 2) & 255 )) ;;
368		(3)	(( o = x & 255 ))
369			p=0
370			;;
371		}
372		t+=\\x${o#16#}
373		(( ++j & 4095 )) && \\builtin continue
374		\\builtin print -n $t
375		t=
376	done
377	\\builtin print -n $t
378}
379function Lb64encode {
380	\\builtin set +U
381	\\builtin typeset c s t table
382	\\builtin set -A table -- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
383	    a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /
384	if (( $# )); then
385		\\builtin read -raN-1 s <<<"$*"
386		\\builtin unset s[${#s[*]}-1]
387	else
388		\\builtin read -raN-1 s
389	fi
390	\\builtin typeset -i i=0 n=${#s[*]} v
391
392	while (( i < n )); do
393		(( v = s[i++] << 16 ))
394		(( v |= s[i++] << 8 ))
395		(( v |= s[i++] ))
396		t+=${table[v >> 18]}${table[v >> 12 & 63]}
397		c=${table[v >> 6 & 63]}
398		if (( i <= n )); then
399			t+=$c${table[v & 63]}
400		elif (( i == n + 1 )); then
401			t+=$c=
402		else
403			t+===
404		fi
405		if (( ${#t} == 76 || i >= n )); then
406			\\builtin print -r $t
407			t=
408		fi
409	done
410}
411
412# Better Avalanche for the Jenkins Hash
413\\builtin typeset -Z11 -Uui16 Lbafh_v
414function Lbafh_init {
415	Lbafh_v=0
416}
417function Lbafh_add {
418	\\builtin set +U
419	\\builtin typeset s
420	if (( $# )); then
421		\\builtin read -raN-1 s <<<"$*"
422		\\builtin unset s[${#s[*]}-1]
423	else
424		\\builtin read -raN-1 s
425	fi
426	\\builtin typeset -i i=0 n=${#s[*]}
427
428	while (( i < n )); do
429		((# Lbafh_v = (Lbafh_v + s[i++] + 1) * 1025 ))
430		((# Lbafh_v ^= Lbafh_v >> 6 ))
431	done
432}
433function Lbafh_finish {
434	\\builtin typeset -Ui t
435
436	((# t = (((Lbafh_v >> 7) & 0x01010101) * 0x1B) ^ \
437	    ((Lbafh_v << 1) & 0xFEFEFEFE) ))
438	((# Lbafh_v = t ^ (t ^> 8) ^ (Lbafh_v ^> 8) ^ \
439	    (Lbafh_v ^> 16) ^ (Lbafh_v ^> 24) ))
440	\:
441}
442
443# strip comments (and leading/trailing whitespace if IFS is set) from
444# any file(s) given as argument, or stdin if none, and spew to stdout
445function Lstripcom {
446	\\builtin set -o noglob
447	\\builtin cat "$@" | while \\builtin read _line; do
448		_line=${_line%%#*}
449		[[ -n $_line ]] && \\builtin print -r -- $_line
450	done
451}
452
453# toggle built-in aliases and utilities, and aliases and functions from mkshrc
454function enable {
455	\\builtin typeset doprnt=0 mode=1 x y z rv=0
456	\\builtin typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all
457	\\builtin set -A b_alias
458	\\builtin set -A i_alias
459	\\builtin set -A i_func
460
461	# accumulate mksh built-in aliases, in ASCIIbetical order
462	i_alias[nalias]=autoload; b_alias[nalias++]='\\builtin typeset -fu'
463	i_alias[nalias]=functions; b_alias[nalias++]='\\builtin typeset -f'
464	i_alias[nalias]=hash; b_alias[nalias++]='\\builtin alias -t'
465	i_alias[nalias]=history; b_alias[nalias++]='\\builtin fc -l'
466	i_alias[nalias]=integer; b_alias[nalias++]='\\builtin typeset -i'
467	i_alias[nalias]=local; b_alias[nalias++]='\\builtin typeset'
468	i_alias[nalias]=login; b_alias[nalias++]='\\builtin exec login'
469	i_alias[nalias]=nameref; b_alias[nalias++]='\\builtin typeset -n'
470	i_alias[nalias]=nohup; b_alias[nalias++]='nohup '
471	i_alias[nalias]=r; b_alias[nalias++]='\\builtin fc -e -'
472	i_alias[nalias]=type; b_alias[nalias++]='\\builtin whence -v'
473
474	# accumulate mksh built-in utilities, in definition order, even ifndef
475	i_func[nfunc++]=.
476	i_func[nfunc++]=:
477	i_func[nfunc++]='['
478	i_func[nfunc++]=alias
479	i_func[nfunc++]=break
480	# \\builtin cannot, by design, be overridden
481	i_func[nfunc++]=builtin
482	i_func[nfunc++]=cat
483	i_func[nfunc++]=cd
484	i_func[nfunc++]=chdir
485	i_func[nfunc++]=command
486	i_func[nfunc++]=continue
487	i_func[nfunc++]=echo
488	i_func[nfunc++]=eval
489	i_func[nfunc++]=exec
490	i_func[nfunc++]=exit
491	i_func[nfunc++]=export
492	i_func[nfunc++]=false
493	i_func[nfunc++]=fc
494	i_func[nfunc++]=getopts
495	i_func[nfunc++]=jobs
496	i_func[nfunc++]=kill
497	i_func[nfunc++]=let
498	i_func[nfunc++]=print
499	i_func[nfunc++]=pwd
500	i_func[nfunc++]=read
501	i_func[nfunc++]=readonly
502	i_func[nfunc++]=realpath
503	i_func[nfunc++]=rename
504	i_func[nfunc++]=return
505	i_func[nfunc++]=set
506	i_func[nfunc++]=shift
507	i_func[nfunc++]=source
508	i_func[nfunc++]=suspend
509	i_func[nfunc++]=test
510	i_func[nfunc++]=times
511	i_func[nfunc++]=trap
512	i_func[nfunc++]=true
513	i_func[nfunc++]=typeset
514	i_func[nfunc++]=ulimit
515	i_func[nfunc++]=umask
516	i_func[nfunc++]=unalias
517	i_func[nfunc++]=unset
518	i_func[nfunc++]=wait
519	i_func[nfunc++]=whence
520	i_func[nfunc++]=bg
521	i_func[nfunc++]=fg
522	i_func[nfunc++]=bind
523	i_func[nfunc++]=mknod
524	i_func[nfunc++]=printf
525	i_func[nfunc++]=sleep
526	i_func[nfunc++]=domainname
527	i_func[nfunc++]=extproc
528
529	# accumulate aliases from dot.mkshrc, in definition order
530	i_alias[nalias]=l; b_alias[nalias++]='ls -F'
531	i_alias[nalias]=la; b_alias[nalias++]='l -a'
532	i_alias[nalias]=ll; b_alias[nalias++]='l -l'
533	i_alias[nalias]=lo; b_alias[nalias++]='l -alo'
534	i_alias[nalias]=doch; b_alias[nalias++]='sudo mksh -c "$(\\builtin fc -ln -1)"'
535	i_alias[nalias]=rot13; b_alias[nalias++]='tr abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
536	i_alias[nalias]=cls; b_alias[nalias++]='\\builtin print -n \\ec'
537
538	# accumulate functions from dot.mkshrc, in definition order
539	i_func[nfunc++]=setenv
540	i_func[nfunc++]=smores
541	i_func[nfunc++]=hd
542	i_func[nfunc++]=hd_mksh
543	i_func[nfunc++]=which
544	i_func[nfunc++]=chpwd
545	i_func[nfunc++]=cd
546	i_func[nfunc++]=cd_csh
547	i_func[nfunc++]=dirs
548	i_func[nfunc++]=popd
549	i_func[nfunc++]=pushd
550	i_func[nfunc++]=Lb64decode
551	i_func[nfunc++]=Lb64encode
552	i_func[nfunc++]=Lbafh_init
553	i_func[nfunc++]=Lbafh_add
554	i_func[nfunc++]=Lbafh_finish
555	i_func[nfunc++]=Lstripcom
556	i_func[nfunc++]=enable
557
558	# collect all identifiers, sorted ASCIIbetically
559	\\builtin set -sA i_all -- "${i_alias[@]}" "${i_func[@]}"
560
561	# handle options, we don't do dynamic loading
562	while \\builtin getopts "adf:nps" x; do
563		case $x {
564		(a)
565			mode=-1
566			;;
567		(d)
568			# deliberately causing an error, like bash-static
569			;|
570		(f)
571			\\builtin print -ru2 enable: dynamic loading not available
572			\\builtin return 2
573			;;
574		(n)
575			mode=0
576			;;
577		(p)
578			doprnt=1
579			;;
580		(s)
581			\\builtin set -sA i_all -- . : break continue eval \
582			    exec exit export readonly return set shift times \
583			    trap unset
584			;;
585		(*)
586			\\builtin print -ru2 enable: usage: \
587			    "enable [-adnps] [-f filename] [name ...]"
588			return 2
589			;;
590		}
591	done
592	\\builtin shift $((OPTIND - 1))
593
594	# display builtins enabled/disabled/all/special?
595	if (( doprnt || ($# == 0) )); then
596		for x in "${i_all[@]}"; do
597			y=$(\\builtin alias "$x") || y=
598			[[ $y = "$x='\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)'" ]]; z=$?
599			case $mode:$z {
600			(-1:0|0:0)
601				\\builtin print -r -- "enable -n $x"
602				;;
603			(-1:1|1:1)
604				\\builtin print -r -- "enable $x"
605				;;
606			}
607		done
608		\\builtin return 0
609	fi
610
611	for x in "$@"; do
612		z=0
613		for y in "${i_alias[@]}" "${i_func[@]}"; do
614			[[ $x = "$y" ]] || \\builtin continue
615			z=1
616			\\builtin break
617		done
618		if (( !z )); then
619			\\builtin print -ru2 enable: "$x": not a shell builtin
620			rv=1
621			\\builtin continue
622		fi
623		if (( !mode )); then
624			# disable this
625			\\builtin alias "$x=\\\\builtin whence -p $x >/dev/null || (\\\\builtin print -r mksh: $x: not found; \\\\builtin exit 127) && \$(\\\\builtin whence -p $x)"
626		else
627			# find out if this is an alias or not, first
628			z=0
629			y=-1
630			while (( ++y < nalias )); do
631				[[ $x = "${i_alias[y]}" ]] || \\builtin continue
632				z=1
633				\\builtin break
634			done
635			if (( z )); then
636				# re-enable the original alias body
637				\\builtin alias "$x=${b_alias[y]}"
638			else
639				# re-enable the original utility/function
640				\\builtin unalias "$x"
641			fi
642		fi
643	done
644	\\builtin return $rv
645}
646
647\: place customisations below this line
648
649# some defaults / samples which you are supposed to adjust to your
650# liking; by default we add ~/.etc/bin and ~/bin (whichever exist)
651# to $PATH, set $SHELL to mksh, set some defaults for man and less
652# and show a few more possible things for users to begin moving in
653
654for p in ~/.etc/bin ~/bin; do
655	[[ -d $p/. ]] || \\builtin continue
656	[[ $PATHSEP$PATH$PATHSEP = *"$PATHSEP$p$PATHSEP"* ]] || \
657	    PATH=$p$PATHSEP$PATH
658done
659
660\\builtin export SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=-
661\\builtin alias cls='\\builtin print -n \\ec'
662
663#\\builtin unset LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
664#    LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
665#    LC_TELEPHONE LC_TIME LANGUAGE LANG LC_ALL
666#p=en_GB.UTF-8
667#\\builtin export LANG=C LC_CTYPE=$p LC_MEASUREMENT=$p LC_MESSAGES=$p LC_PAPER=$p
668#\\builtin export LANG=C.UTF-8 LC_CTYPE=C.UTF-8
669#\\builtin export LC_ALL=C.UTF-8
670#\\builtin set -U
671#[[ ${LC_ALL:-${LC_CTYPE:-${LANG:-}}} = *[Uu][Tt][Ff]?(-)8* ]] || \\builtin set +U
672
673\\builtin unset p
674
675\: place customisations above this line
676