Compare commits
1 Commits
8fbb496b0d
...
0a37a2be59
Author | SHA1 | Date | |
---|---|---|---|
0a37a2be59 |
@ -11,9 +11,9 @@ _autoenv_entered=()
|
||||
_autoenv_enter() {
|
||||
local entered=$1
|
||||
# If entered has already been sourced, return.
|
||||
(( ${+_autoenv_entered[${_autoenv_entered[(i)$entered]}]} )) && return
|
||||
(( ${+_autoenv_entered[$entered]} )) && return
|
||||
# If the enter script is not authorized, return.
|
||||
# TODO: _autoenv_authorized $entered/.enter || return
|
||||
_autoenv_authorized $entered/.enter || return
|
||||
# Source the enter script.
|
||||
source $entered/.enter
|
||||
# Add the entered directory to the global entered array.
|
||||
@ -25,11 +25,11 @@ _autoenv_enter() {
|
||||
_autoenv_exit() {
|
||||
local entered=$1
|
||||
# If the exit script is not authorized, return.
|
||||
# TODO: _autoenv_authorized $entered/.exit || return
|
||||
_autoenv_authorized $entered/.exit || return
|
||||
# Source the exit script.
|
||||
source $entered/.exit
|
||||
# Remove the entered directory from the global entered array.
|
||||
_autoenv_entered[${_autoenv_entered[(i)$entered]}]=()
|
||||
_autoenv_entered-=$entered
|
||||
}
|
||||
|
||||
# Find a directory containing a .enter file by searching up the directory tree
|
||||
@ -37,7 +37,7 @@ _autoenv_exit() {
|
||||
_autoenv_find_enter() {
|
||||
local current=$PWD
|
||||
# If an enter script is found in the current directory, return it.
|
||||
[ -f "$current/.enter" ] && echo $current
|
||||
[ -f $current/.enter ] && return $current
|
||||
# Loop until an enter script or the root directory is found.
|
||||
while true; do
|
||||
# Walk up one directory and make the path absolute.
|
||||
@ -45,7 +45,7 @@ _autoenv_find_enter() {
|
||||
# If the current directory equals the next directory, return.
|
||||
[[ $current == $next ]] && return || local current=$next
|
||||
# If an enter script is found in the current directory, return it.
|
||||
[ -f $current/.enter ] && echo $current
|
||||
[ -f $current/.enter ] && return $current
|
||||
done
|
||||
}
|
||||
|
||||
@ -54,20 +54,21 @@ _autoenv_find_enter() {
|
||||
_autoenv_chpwd() {
|
||||
local entered
|
||||
# Loop over the entered directory stack.
|
||||
for entered in $_autoenv_entered; do
|
||||
for entered in _autoenv_entered; do
|
||||
# If the the current directory was previously entered then exit.
|
||||
# TODO: Verify what this condition expression actually does.
|
||||
! [[ $PWD/ == $entered/* ]] && _autoenv_exit $entered
|
||||
done
|
||||
# Find the nearest enter script directory.
|
||||
local enter=`_autoenv_find_enter`
|
||||
# If the enter directory exists, enter it.
|
||||
[ -d "$enter" ] && _autoenv_enter $enter
|
||||
# If the enter file doesn't exist, return.
|
||||
! [ -f $enter ] $enter && return
|
||||
_autoenv_enter $enter
|
||||
}
|
||||
|
||||
# Register the autoenv chpwd hook.
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook chpwd _autoenv_chpwd
|
||||
add-zsh-hook _autoenv_chpwd
|
||||
|
||||
# Ensure autoenv is activated in the current directory on first load.
|
||||
_autoenv_chpwd
|
||||
|
Loading…
x
Reference in New Issue
Block a user