• reduce number of readlink(1) / realpath(3) calls by caching the result of
running it on “~/.” (must be a directory) in a global readonly variable • if readlink fails, use some more or less sane values (no idea what csh(1) does in these cases, maybe some feedback here?) • optimise, while here
This commit is contained in:
parent
9533756d25
commit
1086ebe83f
29
dot.mkshrc
29
dot.mkshrc
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.21 2007/09/25 15:48:45 tg Stab $
|
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.22 2007/09/25 22:36:36 tg Stab $
|
||||||
#-
|
#-
|
||||||
# Copyright (c) 2007
|
# Copyright (c) 2007
|
||||||
# Thorsten Glaser <tg@mirbsd.de>
|
# Thorsten Glaser <tg@mirbsd.de>
|
||||||
@ -59,14 +59,13 @@ whence -p hd >&- || function hd {
|
|||||||
|
|
||||||
# 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=$(readlink -nf ~/. 2>&- || print -nr -- "$HOME")
|
||||||
|
typeset -r DIRSTACKBASE
|
||||||
set -A DIRSTACK
|
set -A DIRSTACK
|
||||||
function chpwd {
|
function chpwd {
|
||||||
typeset d thome
|
DIRSTACK[0]=$(readlink -nf . 2>&- || print -nr -- "$PWD")
|
||||||
|
[[ ${DIRSTACK[0]#$DIRSTACKBASE} = ${DIRSTACK[0]} ]] || \
|
||||||
d=$(readlink -nf .)
|
DIRSTACK[0]=\~${DIRSTACK[0]#$DIRSTACKBASE}
|
||||||
thome=$(readlink -nf ~/.)
|
|
||||||
DIRSTACK[0]=$d
|
|
||||||
[[ ${d##$thome} = $d ]] || DIRSTACK[0]=\~${d##$thome}
|
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
chpwd .
|
chpwd .
|
||||||
@ -77,7 +76,7 @@ function cd {
|
|||||||
function cd_csh {
|
function cd_csh {
|
||||||
typeset d t=$1
|
typeset d t=$1
|
||||||
|
|
||||||
[[ $t = ~* ]] && t=$HOME${t#~}
|
[[ $t = ~* ]] && t=$DIRSTACKBASE${t#~}
|
||||||
if ! d=$(builtin cd "$t" 2>&1); then
|
if ! d=$(builtin cd "$t" 2>&1); then
|
||||||
print -u2 "${1}: ${d##*$t - }."
|
print -u2 "${1}: ${d##*$t - }."
|
||||||
return 1
|
return 1
|
||||||
@ -108,9 +107,7 @@ function dirs {
|
|||||||
fv=0
|
fv=0
|
||||||
while (( fv < ${#DIRSTACK[*]} )); do
|
while (( fv < ${#DIRSTACK[*]} )); do
|
||||||
d=${DIRSTACK[fv]}
|
d=${DIRSTACK[fv]}
|
||||||
if [[ $fl$d = 1~* ]]; then
|
[[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
|
||||||
d=$HOME${d#~}
|
|
||||||
fi
|
|
||||||
print -r -- "$fv $d"
|
print -r -- "$fv $d"
|
||||||
let fv++
|
let fv++
|
||||||
done
|
done
|
||||||
@ -118,10 +115,8 @@ function dirs {
|
|||||||
fv=0
|
fv=0
|
||||||
while (( fv < ${#DIRSTACK[*]} )); do
|
while (( fv < ${#DIRSTACK[*]} )); do
|
||||||
d=${DIRSTACK[fv]}
|
d=${DIRSTACK[fv]}
|
||||||
if [[ $fl$d = 1~* ]]; then
|
[[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
|
||||||
d=$HOME${d#~}
|
if (( fn && (cpos+=${#d}+1) >= 79 && ${#d} < 80 )); then
|
||||||
fi
|
|
||||||
if (( fn && (cpos += ${#d} + 1) >= 79 && ${#d} < 80 )); then
|
|
||||||
print
|
print
|
||||||
(( cpos = ${#d} + 1 ))
|
(( cpos = ${#d} + 1 ))
|
||||||
fi
|
fi
|
||||||
@ -134,7 +129,7 @@ function dirs {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
function popd {
|
function popd {
|
||||||
typeset d fa=""
|
typeset d fa
|
||||||
typeset -i isnoglob=0 n=1
|
typeset -i isnoglob=0 n=1
|
||||||
|
|
||||||
[[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
|
[[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
|
||||||
@ -173,7 +168,7 @@ function popd {
|
|||||||
dirs $fa
|
dirs $fa
|
||||||
}
|
}
|
||||||
function pushd {
|
function pushd {
|
||||||
typeset d fa=""
|
typeset d fa
|
||||||
typeset -i isnoglob=0 n=1
|
typeset -i isnoglob=0 n=1
|
||||||
|
|
||||||
[[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
|
[[ $(set +o) == *-o\ noglob* ]] && isnoglob=1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user