source: freewrt/package/mksh/patches/patch-dot_mkshrc@ ec960dd

freewrt_1_0 freewrt_2_0
Last change on this file since ec960dd was ec960dd, checked in by Thorsten Glaser <tg@…>, 18 years ago

MFC: mksh R28 → R31c+20070926

Reason: the busy-loop problem, which was fixed in R31b, was discovered

by spaetzle@ even doing some simpler pattern matching; also cf.
http://bugs.debian.org/296446 and http://mirbsd.de/mksh#clog

Side effects:

  • you can now select to build a full-featured mksh in menuconfig (still defaults to ‘n’, as does mksh itself)
  • the new dot.mkshrc file offers pushd/popd/dirs (csh-like) as well as the precmd() and chpwd() hooks (zsh-like)
  • added dependency on busybox: “readlink -f”
  • UI still the same, except no $? in $PS1 any more (req. by yofuh)
  • /etc/mkshrc is now an ipkg conffile and handled appropriately
  • building with pcc should be possible (if you turn optimisation off)

Tested:

  • FreeWRT 1.0-stable, ASUS WL-500g, mksh as /bin/sh+/bin/ash full-featured
  • FreeWRT-current (by spaetzle@) before the MFC

git-svn-id: svn://www.freewrt.org/branches/freewrt_1_0@3582 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 6.6 KB
Line 
1$FreeWRT$
2
3 • bring mksh to the level of 2007/09/26
4 • FreeWRT patches:
5 – no hostname(1)
6 – ls has no -o
7 – yofuh doesn’t like $? in $PS1
8
9--- mksh.orig/dot.mkshrc 2007-09-03 09:25:28.000000000 +0000
10+++ mksh/dot.mkshrc 2007-09-26 17:52:20.000000000 +0000
11@@ -1,8 +1,41 @@
12-: ${EDITOR:=/bin/ed} ${TERM:=vt100} ${HOSTNAME:=$(ulimit -c 0;hostname -s 2>&-)}
13+# $MirOS: src/bin/mksh/dot.mkshrc,v 1.22 2007/09/25 22:36:36 tg Stab $
14+#-
15+# Copyright (c) 2007
16+# Thorsten Glaser <tg@mirbsd.de>
17+#
18+# Provided that these terms and disclaimer and all copyright notices
19+# are retained or reproduced in an accompanying document, permission
20+# is granted to deal in this work without restriction, including un-
21+# limited rights to use, publicly perform, distribute, sell, modify,
22+# merge, give away, or sublicence.
23+#
24+# Advertising materials mentioning features or use of this work must
25+# display the following acknowledgement:
26+# This product includes material provided by Thorsten Glaser.
27+#
28+# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
29+# the utmost extent permitted by applicable law, neither express nor
30+# implied; without malicious intent or gross negligence. In no event
31+# may a licensor, author or contributor be held liable for indirect,
32+# direct, other damage, loss, or other issues arising in any way out
33+# of dealing in the work, even if advised of the possibility of such
34+# damage or existence of a defect, except proven that it results out
35+# of said person's immediate fault when using the work as intended.
36+#-
37+# sample mksh initialisation file for interactive shells
38+
39+: ${EDITOR:=/bin/ed} ${TERM:=vt100} ${HOSTNAME:=$(</proc/sys/kernel/hostname)}
40 [[ $HOSTNAME = @(localhost|*([ ])) ]] && HOSTNAME=$(ulimit -c 0;hostname 2>&-)
41 : ${HOSTNAME:=nil}; PS1='#'; [[ "$(ulimit -c 0; id -u 2>&-)" -eq 0 ]] || PS1='$'
42-PS1='$(((e = $?)) && print $e\|)${USER:=$(ulimit -c 0; id -un 2>&- || \
43- print nobody)}@${HOSTNAME%%.*}:$(typeset pfx=~ wd=${PWD:-?}
44+function precmd {
45+ typeset -i10 e=$?
46+
47+# enable this back if you want the errorlevel in your prompt
48+# this is default in upstream mksh
49+# (( e )) && print -n -- "$e|"
50+}
51+PS1='$(precmd)${USER:=$(ulimit -c 0;id -un 2>&- || print \?)}@${HOSTNAME%%.*}:$(
52+ typeset pfx=~ wd=${PWD:-?}
53 typeset -i n=${COLUMNS:-80}/3; let n="n < 7 ? 7 : n"
54 [[ ${wd#$pfx} = $wd || $pfx = ?(/) ]] || wd=\~${wd#$pfx}
55 pfx=; while (( (${#pfx} + ${#wd}) > n )); do
56@@ -18,7 +51,7 @@ export EDITOR HOSTNAME LESSHISTFILE=- MK
57 alias l='/bin/ls -F'
58 alias la='l -a'
59 alias ll='l -l'
60-alias lo='la -lo'
61+alias lo='la -l'
62 alias which='whence -p'
63 whence -p rot13 >&- || alias rot13='tr [A-Za-z] [N-ZA-Mn-za-m]'
64 whence -p hd >&- || function hd {
65@@ -26,6 +59,162 @@ whence -p hd >&- || function hd {
66 -e '" |" "%_p"' -e '"|\n"' "$@"
67 }
68
69+# Berkeley C shell compatible dirs, popd, and pushd functions
70+# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
71+DIRSTACKBASE=$(readlink -nf ~/. 2>&- || print -nr -- "$HOME")
72+typeset -r DIRSTACKBASE
73+set -A DIRSTACK
74+function chpwd {
75+ DIRSTACK[0]=$(readlink -nf . 2>&- || print -nr -- "$PWD")
76+ [[ ${DIRSTACK[0]#$DIRSTACKBASE} = ${DIRSTACK[0]} ]] || \
77+ DIRSTACK[0]=\~${DIRSTACK[0]#$DIRSTACKBASE}
78+ :
79+}
80+chpwd .
81+function cd {
82+ builtin cd "$@"
83+ chpwd "$@"
84+}
85+function cd_csh {
86+ typeset d t=$1
87+
88+ [[ $t = ~* ]] && t=$DIRSTACKBASE${t#~}
89+ if ! d=$(builtin cd "$t" 2>&1); then
90+ print -u2 "${1}: ${d##*$t - }."
91+ return 1
92+ fi
93+ cd "$t"
94+}
95+function dirs {
96+ typeset d
97+ typeset -i isnoglob=0 fl=0 fv=0 fn=0 cpos=0
98+
99+ [[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
100+ set -o noglob
101+ while getopts ":lvn" d; do
102+ case $d {
103+ (l) fl=1 ;;
104+ (v) fv=1 ;;
105+ (n) fn=1 ;;
106+ (*) print -u2 'Usage: dirs [-lvn].'
107+ return 1 ;;
108+ }
109+ done
110+ shift $((OPTIND - 1))
111+ if (( $# > 0 )); then
112+ print -u2 'Usage: dirs [-lvn].'
113+ return 1
114+ fi
115+ if (( fv )); then
116+ fv=0
117+ while (( fv < ${#DIRSTACK[*]} )); do
118+ d=${DIRSTACK[fv]}
119+ [[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
120+ print -r -- "$fv $d"
121+ let fv++
122+ done
123+ else
124+ fv=0
125+ while (( fv < ${#DIRSTACK[*]} )); do
126+ d=${DIRSTACK[fv]}
127+ [[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
128+ if (( fn && (cpos+=${#d}+1) >= 79 && ${#d} < 80 )); then
129+ print
130+ (( cpos = ${#d} + 1 ))
131+ fi
132+ print -nr -- "$d "
133+ let fv++
134+ done
135+ print
136+ fi
137+ (( isnoglob )) || set +o noglob
138+ return 0
139+}
140+function popd {
141+ typeset d fa
142+ typeset -i isnoglob=0 n=1
143+
144+ [[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
145+ set -o noglob
146+ while getopts ":0123456789lvn" d; do
147+ case $d {
148+ (l|v|n) fa="$fa -$d" ;;
149+ (+*) n=2
150+ break ;;
151+ (*) print -u2 'Usage: popd [-lvn] [+<n>].'
152+ return 1 ;;
153+ }
154+ done
155+ shift $((OPTIND - n))
156+ n=0
157+ if (( $# > 1 )); then
158+ print -u2 popd: Too many arguments.
159+ return 1
160+ elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
161+ if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
162+ print -u2 popd: Directory stack not that deep.
163+ return 1
164+ fi
165+ elif [[ -n $1 ]]; then
166+ print -u2 popd: Bad directory.
167+ return 1
168+ fi
169+ if (( ${#DIRSTACK[*]} < 2 )); then
170+ print -u2 popd: Directory stack empty.
171+ return 1
172+ fi
173+ unset DIRSTACK[n]
174+ set -A DIRSTACK -- "${DIRSTACK[@]}"
175+ cd_csh "${DIRSTACK[0]}" || return 1
176+ (( isnoglob )) || set +o noglob
177+ dirs $fa
178+}
179+function pushd {
180+ typeset d fa
181+ typeset -i isnoglob=0 n=1
182+
183+ [[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
184+ set -o noglob
185+ while getopts ":0123456789lvn" d; do
186+ case $d {
187+ (l|v|n) fa="$fa -$d" ;;
188+ (+*) n=2
189+ break ;;
190+ (*) print -u2 'Usage: pushd [-lvn] [<dir>|+<n>].'
191+ return 1 ;;
192+ }
193+ done
194+ shift $((OPTIND - n))
195+ if (( $# == 0 )); then
196+ if (( ${#DIRSTACK[*]} < 2 )); then
197+ print -u2 pushd: No other directory.
198+ return 1
199+ fi
200+ d=${DIRSTACK[1]}
201+ DIRSTACK[1]=${DIRSTACK[0]}
202+ cd_csh "$d" || return 1
203+ elif (( $# > 1 )); then
204+ print -u2 pushd: Too many arguments.
205+ return 1
206+ elif [[ $1 = ++([0-9]) && $1 != +0 ]]; then
207+ if (( (n = ${1#+}) >= ${#DIRSTACK[*]} )); then
208+ print -u2 pushd: Directory stack not that deep.
209+ return 1
210+ fi
211+ while (( n-- )); do
212+ d=${DIRSTACK[0]}
213+ unset DIRSTACK[0]
214+ set -A DIRSTACK -- "${DIRSTACK[@]}" "$d"
215+ done
216+ cd_csh "${DIRSTACK[0]}" || return 1
217+ else
218+ set -A DIRSTACK -- placeholder "${DIRSTACK[@]}"
219+ cd_csh "$1" || return 1
220+ fi
221+ (( isnoglob )) || set +o noglob
222+ dirs $fa
223+}
224+
225 # strip comments (and leading/trailing whitespace if IFS is set) from
226 # any file(s) given as argument, or stdin if none, and spew to stdout
227 function Lstripcom {
228@@ -35,6 +224,4 @@ function Lstripcom {
229 done; }
230 }
231
232-# place customisations between this line and the “: RCSID” line below
233-
234-: $MirOS: src/bin/mksh/dot.mkshrc,v 1.19 2007/09/03 09:25:05 tg Rel $
235+: place customsations above this line!
Note: See TracBrowser for help on using the repository browser.