]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
_autoenv_get_file_upwards: handle relative paths
authorDaniel Hahler <git@thequod.de>
Fri, 11 Aug 2017 08:26:38 +0000 (10:26 +0200)
committerDaniel Hahler <git@thequod.de>
Fri, 11 Aug 2017 08:27:20 +0000 (10:27 +0200)
If `$look_from` is `.` the resulting file patch will be relative.

autoenv.zsh
tests/_autoenv_utils.t

index db059f292e319a81f36296d9e7907f3c09d7c040..c7a2999be5ea2f4d8348dcdf960f2e55b3605631 100644 (file)
@@ -330,19 +330,24 @@ _autoenv_get_file_upwards() {
   # performance reasons, which is only available in zsh-5.0.5-146-g9381bb6.
   local last
   local parent_dir="$look_from/.."
+  local abs_parent_dir
   while true; do
-    parent_dir=${parent_dir:A}
-    if [[ $parent_dir == $last ]]; then
+    abs_parent_dir=${parent_dir:A}
+    if [[ $abs_parent_dir == $last ]]; then
       break
     fi
     local parent_file="${parent_dir}/${look_for}"
 
     if [[ -f $parent_file ]]; then
-      echo $parent_file
+      if [[ ${parent_file[1,2]} == './' ]]; then
+        echo ${parent_file#./}
+      else
+        echo ${parent_file:A}
+      fi
       break
     fi
 
-    if [[ $parent_dir == $look_until ]]; then
+    if [[ $abs_parent_dir == $look_until ]]; then
       break
     fi
     last=$parent_dir
index f4f2e2ce6dae04eb4b094f5a86576a3c516dc01c..a23f18990528157f63306dbd574b2723b74c64ef 100644 (file)
@@ -13,6 +13,8 @@ Should not get the file from the current dir.
 
   $ cd sub/sub2
   $ _autoenv_get_file_upwards . file
+  ../file
+  $ _autoenv_get_file_upwards $PWD file
   */_autoenv_utils.t/sub/file (glob)