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