1
0
mirror of https://github.com/Tarrasch/zsh-autoenv.git synced 2024-11-22 07:20:59 +02:00

Merge pull request #71 from blueyed/minor

Minor code cleanup/optimization
This commit is contained in:
Daniel Hahler 2017-10-18 00:32:08 +02:00 committed by GitHub
commit 2db6d69774

View File

@ -72,14 +72,12 @@ _autoenv_stack_entered_add() {
# Remove any existing entry. # Remove any existing entry.
_autoenv_stack_entered_remove $env_file _autoenv_stack_entered_remove $env_file
_autoenv_debug "[stack] adding: $env_file" 2
# Append it to the stack, and remember its mtime. # Append it to the stack, and remember its mtime.
_autoenv_debug "[stack] adding: $env_file" 2
_autoenv_stack_entered+=($env_file) _autoenv_stack_entered+=($env_file)
_autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file) _autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file)
} }
# zstat_mime helper, conditionally defined. # zstat_mime helper, conditionally defined.
# Load zstat module, but only its builtin `zstat`. # Load zstat module, but only its builtin `zstat`.
if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
@ -102,7 +100,6 @@ else
} }
fi fi
# Remove an entry from the stack. # Remove an entry from the stack.
_autoenv_stack_entered_remove() { _autoenv_stack_entered_remove() {
local env_file=$1 local env_file=$1
@ -140,11 +137,11 @@ _autoenv_stack_entered_contains() {
# Internal function for debug output. {{{ # Internal function for debug output. {{{
_autoenv_debug() { _autoenv_debug() {
local msg="$1" # Might trigger a bug in Zsh 5.0.5 with shwordsplit.
local level=${2:-1} local level=${2:-1}
if [[ $AUTOENV_DEBUG -lt $level ]]; then if (( AUTOENV_DEBUG < level )); then
return return
fi fi
local msg="$1" # Might trigger a bug in Zsh 5.0.5 with shwordsplit.
# Load zsh color support. # Load zsh color support.
if [[ -z $color ]]; then if [[ -z $color ]]; then
autoload colors autoload colors
@ -293,7 +290,7 @@ _autoenv_source() {
# XXX: pollutes environment with e.g. `stash`, and `autostash` will cause # XXX: pollutes environment with e.g. `stash`, and `autostash` will cause
# an overwritten `stash` function to be called! # an overwritten `stash` function to be called!
if ! (( $+functions[autostash] )); then if ! (( $+functions[autostash] )); then
if \grep -qE '\b(autostash|autounstash|stash)\b' $autoenv_env_file; then if \grep -qE '\b(autostash|autounstash|stash|unstash)\b' $autoenv_env_file; then
source ${${funcsourcetrace[1]%:*}:h}/lib/varstash source ${${funcsourcetrace[1]%:*}:h}/lib/varstash
fi fi
# NOTE: Varstash uses $PWD as default for varstash_dir, we might set it to # NOTE: Varstash uses $PWD as default for varstash_dir, we might set it to
@ -302,7 +299,7 @@ _autoenv_source() {
# Source the env file. # Source the env file.
_autoenv_debug "== SOURCE: ${bold_color:-}$autoenv_env_file${reset_color:-}\n PWD: $PWD" _autoenv_debug "== SOURCE: ${bold_color:-}$autoenv_env_file${reset_color:-}\n PWD: $PWD"
: $(( _autoenv_debug_indent++ )) (( ++_autoenv_debug_indent ))
local restore_xtrace local restore_xtrace
if [[ $AUTOENV_DEBUG -gt 2 && ! -o xtrace ]]; then if [[ $AUTOENV_DEBUG -gt 2 && ! -o xtrace ]]; then
@ -313,7 +310,7 @@ _autoenv_source() {
if (( restore_xtrace )); then if (( restore_xtrace )); then
setopt noxtrace setopt noxtrace
fi fi
: $(( _autoenv_debug_indent-- )) (( --_autoenv_debug_indent ))
_autoenv_debug "== END SOURCE ==" _autoenv_debug "== END SOURCE =="
if [[ $autoenv_event == enter ]]; then if [[ $autoenv_event == enter ]]; then
@ -396,7 +393,7 @@ _autoenv_chpwd_handler() {
fi fi
local env_file="$PWD/$AUTOENV_FILE_ENTER" local env_file="$PWD/$AUTOENV_FILE_ENTER"
_autoenv_debug "looking for env_file: $env_file" _autoenv_debug "Looking for env_file: $env_file"
# Handle leave event for previously sourced env files. # Handle leave event for previously sourced env files.
if [[ $AUTOENV_HANDLE_LEAVE == 1 ]] && (( $#_autoenv_stack_entered )); then if [[ $AUTOENV_HANDLE_LEAVE == 1 ]] && (( $#_autoenv_stack_entered )); then
@ -443,7 +440,7 @@ _autoenv_chpwd_handler() {
_autoenv_debug "Sourcing from chpwd handler: $env_file" _autoenv_debug "Sourcing from chpwd handler: $env_file"
_autoenv_source $env_file enter _autoenv_source $env_file enter
: $(( _autoenv_debug_indent++ )) (( ++_autoenv_debug_indent ))
} }
# }}} # }}}