• the \: "${foo:=bar}${bar:=baz}" construct needs no spaces

• more set -u police
• 80c and tweaks while here
This commit is contained in:
tg 2015-04-11 19:01:59 +00:00
parent 451aef7a8a
commit 4ee3269564
1 changed files with 24 additions and 18 deletions

View File

@ -1,5 +1,5 @@
# $Id$ # $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.95 2015/04/11 18:08:56 tg Exp $ # $MirOS: src/bin/mksh/dot.mkshrc,v 1.96 2015/04/11 19:01:59 tg Exp $
#- #-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015 # 2011, 2012, 2013, 2014, 2015
@ -23,16 +23,17 @@
# ${ENV:-~/.mkshrc}: mksh initialisation file for interactive shells # ${ENV:-~/.mkshrc}: mksh initialisation file for interactive shells
# catch non-mksh (including lksh) trying to run this file # catch non-mksh (including lksh) trying to run this file
case $KSH_VERSION in case ${KSH_VERSION:-} in
*MIRBSD\ KSH*) ;; *MIRBSD\ KSH*) ;;
*) return 0 ;; *) return 0 ;;
esac esac
PS1='#'; (( USER_ID )) && PS1='$'; [[ ${HOSTNAME:=$(\ulimit -c 0; hostname -s \ PS1='#'; (( USER_ID )) && PS1='$'; \: "${TERM:=vt100}${HOSTNAME:=$(\ulimit -c \
2>/dev/null)} = *([ ]|localhost) ]] && HOSTNAME=$(\ulimit -c 0; hostname \ 0; hostname 2>/dev/null)}${EDITOR:=/bin/ed}${USER:=$(\ulimit -c 0; id -un \
2>/dev/null); \: "${EDITOR:=/bin/ed} ${HOSTNAME:=nil} ${MKSH:=$(\builtin \ 2>/dev/null || \echo \?)}${MKSH:=$(\builtin whence -p mksh)}"
whence -p mksh || \echo /bin/mksh)} ${TERM:=vt100} ${USER:=$(\ulimit -c 0; \ HOSTNAME=${HOSTNAME%%*([ ]).*}; HOSTNAME=${HOSTNAME##*([ ])}
id -un 2>/dev/null || \echo \?)}" [[ $HOSTNAME = ?(ip6-)localhost?(6) ]] && HOSTNAME=
\: "${HOSTNAME:=nil}${MKSH:=/bin/mksh}"; \export EDITOR HOSTNAME MKSH TERM USER
PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${| PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${|
\typeset e=$? \typeset e=$?
@ -45,7 +46,7 @@ PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${|
REPLY+=$p$d REPLY+=$p$d
\return $e \return $e
} '"$PS1 "; \export EDITOR HOSTNAME MKSH TERM USER } '"$PS1 "
\alias ls=ls \alias ls=ls
\unalias ls \unalias ls
\alias l='ls -F' \alias l='ls -F'
@ -73,7 +74,8 @@ else
while (( i < ${#line[*]} )); do while (( i < ${#line[*]} )); do
hv=${line[i++]} hv=${line[i++]}
if (( (pos & 15) == 0 )); then if (( (pos & 15) == 0 )); then
(( pos )) && \builtin print -r -- "$dasc|" (( pos )) && \
\builtin print -r -- "$dasc|"
\builtin print -n "${pos#16#} " \builtin print -n "${pos#16#} "
dasc=' |' dasc=' |'
fi fi
@ -83,11 +85,13 @@ else
else else
dasc+=${line[i-1]#1#} dasc+=${line[i-1]#1#}
fi fi
(( (pos++ & 15) == 7 )) && \builtin print -n -- '- ' (( (pos++ & 15) == 7 )) && \
\builtin print -n -- '- '
done done
while (( pos & 15 )); do while (( pos & 15 )); do
\builtin print -n ' ' \builtin print -n ' '
(( (pos++ & 15) == 7 )) && \builtin print -n -- '- ' (( (pos++ & 15) == 7 )) && \
\builtin print -n -- '- '
done done
(( hv == 2147483647 )) || \builtin print -r -- "$dasc|" (( hv == 2147483647 )) || \builtin print -r -- "$dasc|"
fi; } fi; }
@ -96,10 +100,12 @@ fi
# Berkeley C shell compatible dirs, popd, and pushd functions # Berkeley C shell compatible dirs, popd, and pushd functions
# Z shell compatible chpwd() hook, used to update DIRSTACK[0] # Z shell compatible chpwd() hook, used to update DIRSTACK[0]
DIRSTACKBASE=$(\builtin realpath ~/. 2>/dev/null || \builtin print -nr -- "${HOME:-/}") DIRSTACKBASE=$(\builtin realpath ~/. 2>/dev/null || \
\builtin print -nr -- "${HOME:-/}")
set -A DIRSTACK set -A DIRSTACK
function chpwd { function chpwd {
DIRSTACK[0]=$(\builtin realpath . 2>/dev/null || \builtin print -r -- "$PWD") DIRSTACK[0]=$(\builtin realpath . 2>/dev/null || \
\builtin print -r -- "$PWD")
[[ $DIRSTACKBASE = ?(*/) ]] || \ [[ $DIRSTACKBASE = ?(*/) ]] || \
DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/~} DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/~}
\: \:
@ -299,7 +305,7 @@ function Lb64decode {
(( u )) || \set -U (( u )) || \set -U
} }
\set -A Lb64encode_code -- 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 \ \set -A Lb64encode_tbl -- 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 \
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 + / 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 + /
function Lb64encode { function Lb64encode {
[[ -o utf8-mode ]]; \typeset u=$? c s t [[ -o utf8-mode ]]; \typeset u=$? c s t
@ -318,10 +324,10 @@ function Lb64encode {
(( v |= j << 8 )) (( v |= j << 8 ))
(( j = i < n ? s[i++] : 0 )) (( j = i < n ? s[i++] : 0 ))
(( v |= j )) (( v |= j ))
t+=${Lb64encode_code[v >> 18]}${Lb64encode_code[v >> 12 & 63]} t+=${Lb64encode_tbl[v >> 18]}${Lb64encode_tbl[v >> 12 & 63]}
c=${Lb64encode_code[v >> 6 & 63]} c=${Lb64encode_tbl[v >> 6 & 63]}
if (( i <= n )); then if (( i <= n )); then
t+=$c${Lb64encode_code[v & 63]} t+=$c${Lb64encode_tbl[v & 63]}
elif (( i == n + 1 )); then elif (( i == n + 1 )); then
t+=$c= t+=$c=
else else
@ -382,7 +388,7 @@ function setenv {
\eval "'export' \"$1\""'="$2"' \eval "'export' \"$1\""'="$2"'
} }
# toggle built-in aliases and utilities, and aliases and functions from here # toggle built-in aliases and utilities, and aliases and functions from mkshrc
function enable { function enable {
\typeset doprnt=0 mode=1 x y z rv=0 \typeset doprnt=0 mode=1 x y z rv=0
\typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all \typeset b_alias i_alias i_func nalias=0 nfunc=0 i_all