mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-22 15:30:59 +02:00
_autoenv_get_file_upwards: handle relative paths
If `$look_from` is `.` the resulting file patch will be relative.
This commit is contained in:
parent
9ecb91480d
commit
b90d2c4f80
13
autoenv.zsh
13
autoenv.zsh
@ -330,19 +330,24 @@ _autoenv_get_file_upwards() {
|
|||||||
# performance reasons, which is only available in zsh-5.0.5-146-g9381bb6.
|
# performance reasons, which is only available in zsh-5.0.5-146-g9381bb6.
|
||||||
local last
|
local last
|
||||||
local parent_dir="$look_from/.."
|
local parent_dir="$look_from/.."
|
||||||
|
local abs_parent_dir
|
||||||
while true; do
|
while true; do
|
||||||
parent_dir=${parent_dir:A}
|
abs_parent_dir=${parent_dir:A}
|
||||||
if [[ $parent_dir == $last ]]; then
|
if [[ $abs_parent_dir == $last ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
local parent_file="${parent_dir}/${look_for}"
|
local parent_file="${parent_dir}/${look_for}"
|
||||||
|
|
||||||
if [[ -f $parent_file ]]; then
|
if [[ -f $parent_file ]]; then
|
||||||
echo $parent_file
|
if [[ ${parent_file[1,2]} == './' ]]; then
|
||||||
|
echo ${parent_file#./}
|
||||||
|
else
|
||||||
|
echo ${parent_file:A}
|
||||||
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $parent_dir == $look_until ]]; then
|
if [[ $abs_parent_dir == $look_until ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
last=$parent_dir
|
last=$parent_dir
|
||||||
|
@ -13,6 +13,8 @@ Should not get the file from the current dir.
|
|||||||
|
|
||||||
$ cd sub/sub2
|
$ cd sub/sub2
|
||||||
$ _autoenv_get_file_upwards . file
|
$ _autoenv_get_file_upwards . file
|
||||||
|
../file
|
||||||
|
$ _autoenv_get_file_upwards $PWD file
|
||||||
*/_autoenv_utils.t/sub/file (glob)
|
*/_autoenv_utils.t/sub/file (glob)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user