blob: 9c3bc25ff4c1426f304dbe7e1ca71e2867093918 (
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
|
function upto --description 'go up in directory tree' --argument expr
if test -z $expr
echo "A directory expression must be provided." >&2
return 1
end
if test $expr = "/"
cd /
return 0
end
set current_dir $PWD
set matched_dir ""
set matching true
while test $matching = "true"
if string match -q "*$expr*" $current_dir
set matched_dir $current_dir
set current_dir (dirname $current_dir)
else
set matching false
end
end
if test -n $matched_dir
cd $matched_dir
return 0
else
echo "No match." >&2
return 1
end
end
|