]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - autoenv.zsh
Add helper functions for $PATH manipulation (#90)
[zsh-autoenv.git] / autoenv.zsh
index a7aaeb40de9e656ec954d80f2064b71a557b3d8a..598443b65bb68ef2d8b016c3af045a82541ae4d5 100644 (file)
@@ -59,6 +59,29 @@ autoenv_source_parent() {
   fi
 }
 
+autoenv_append_path() {
+  local i
+  for i; do
+    (( ${path[(i)$i]} <= ${#path} )) && continue
+    path+=($i)
+  done
+}
+autoenv_prepend_path() {
+  local i
+  for i; do
+    (( ${path[(i)$i]} <= ${#path} )) && continue
+    path=($i $path)
+  done
+}
+autoenv_remove_path() {
+  local i
+  local old_path=$path
+  for i; do
+    path=("${(@)path:#$i}")
+  done
+  [[ $old_path != $path ]]
+}
+
 # Internal functions. {{{
 # Internal: stack of loaded env files (i.e. entered directories). {{{
 typeset -g -a _autoenv_stack_entered
@@ -364,12 +387,13 @@ _autoenv_get_file_upwards() {
     if [[ $abs_parent_dir == $look_until ]]; then
       break
     fi
-    last=$parent_dir
+    last=$abs_parent_dir
     parent_dir="${parent_dir}/.."
   done
 }
 
 autoenv-edit() {
+  emulate -L zsh
   local env_file
   local -a files
   local -A check
@@ -402,6 +426,7 @@ autoenv-edit() {
 }
 
 _autoenv_chpwd_handler() {
+  emulate -L zsh
   _autoenv_debug "Calling chpwd handler: PWD=$PWD"
 
   if (( $AUTOENV_DISABLED )); then