blob: bf08d0004e243705a7069edbd76a6fc78ef72f66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
## vim:ft=zsh
## Needs an absolute directory path as argument
## May not contain ~ or named directories
## CAVEAT: directory-names containing two or more consecutive spaces
## are not yet supported
typeset -a tree expn
typeset result part dir
typeset -i i
#typeset IFS='/'
tree=(${(s:/:)1})
(
if [[ $tree[1] = '~' ]] {
shift tree
cd ~
result='~'
} else {
cd /
}
for dir in $tree; {
expn=(a b)
part=''
i=0
# $i -gt 999 <- See CAVEAT - Onterwise we'd have an endless loop here
until [[ (( ${#expn} == 1 )) || $dir = $expn || $i -gt 999 ]] do
(( i++ ))
part+=$dir[$i]
expn=($(echo ${part}*))
# echo "DEBUG: part=$part"
# echo "DEBUG: expn=${(j:×:)expn}"
# echo "DEBUG: dir=$dir"
done
result+="/$part"
cd $dir
}
echo $result
)
|