Compare commits

..

1 Commits

Author SHA1 Message Date
2e5b8aef8a Add autoenv, automatic environment setup
Using a hook, automatically detect when `.enter` and `.exit` scripts
and source them when changing the shells current directory.
2018-04-22 18:57:26 +01:00

View File

@ -66,8 +66,8 @@ _autoenv_exit() {
_autoenv_entered[${_autoenv_entered[(i)$entered]}]=() _autoenv_entered[${_autoenv_entered[(i)$entered]}]=()
} }
# Find all directories containing a .enter file by searching up the directory # Find a directory containing a .enter file by searching up the directory tree
# tree starting in the current directory. # starting in the current directory.
_autoenv_find_enter_directories() { _autoenv_find_enter_directories() {
local current=$PWD local current=$PWD
# If an enter script is found in the current directory, return it. # If an enter script is found in the current directory, return it.
@ -78,8 +78,7 @@ _autoenv_find_enter_directories() {
local next=$current/..; local next=${next:A} local next=$current/..; local next=${next:A}
# If an enter script is found in the current directory, return it. # If an enter script is found in the current directory, return it.
[ -f $next/.enter ] && echo $next [ -f $next/.enter ] && echo $next
# If the current directory equals the next directory we are done, otherwise # If the current directory equals the next directory, return.
# update the current directory.
[[ $current == $next ]] && return || local current=$next [[ $current == $next ]] && return || local current=$next
done done
} }