use string width, not length, if we have it

This commit is contained in:
tg 2010-07-11 13:54:37 +00:00
parent a6c81ea978
commit 0a5d6bc71b
1 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,5 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.55 2010/07/04 17:35:16 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.56 2010/07/11 13:54:37 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010
# Thorsten Glaser <tg@mirbsd.org>
@ -31,7 +31,7 @@ function precmd {
}
PS1=' $(precmd)${USER:=$(ulimit -c 0;id -un 2>&-||print \?)}@${HOSTNAME%%.*}:$(
typeset d=${PWD:-?} n p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}
(( ${#d} > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && {
(( (${%d}>0 ? ${%d}: ${#d}) > (n = (COLUMNS/3<7 ? 7: COLUMNS/3)) )) && {
d=${d:(-n)}; p=...; } || p=; print -nr -- "$p$d") '"$PS1 "
: ${MKSH:=$(whence -p mksh)}; export EDITOR HOSTNAME MKSH PS1 TERM USER
alias ls=ls
@ -73,7 +73,7 @@ function cd_csh {
cd "$t"
}
function dirs {
typeset d
typeset d dwidth
typeset -i isnoglob=0 fl=0 fv=0 fn=0 cpos=0
[[ $(set +o) == *@(-o noglob)@(| *) ]] && isnoglob=1
@ -105,9 +105,11 @@ function dirs {
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
(( fl )) && d=${d/#~/$DIRSTACKBASE}
if (( fn && (cpos+=${#d}+1) >= 79 && ${#d} < 80 )); then
(( dwidth = (${%d} > 0 ? ${%d} : ${#d}) ))
if (( fn && (cpos += dwidth + 1) >= 79 && \
dwidth < 80 )); then
print
(( cpos = ${#d} + 1 ))
(( cpos = dwidth + 1 ))
fi
print -nr -- "$d "
let fv++