diff --git a/auto-ls.zsh b/auto-ls.zsh index 5d44462..a35e42d 100755 --- a/auto-ls.zsh +++ b/auto-ls.zsh @@ -17,6 +17,8 @@ if (( ! ${+AUTO_LS_PATH} )); then AUTO_LS_PATH=true fi +# Initialize auto-ls activation flag +typeset -g AUTO_LS_INIT_COMPLETE=false auto-ls-ls () { ls --color=auto -a @@ -31,9 +33,14 @@ auto-ls-git-status () { auto-ls () { # Possible invocation sources: - # 1. Called from `chpwd_functions` – show file list - # 2. Called by another ZLE plugin (like `dirhistory`) through `zle accept-line` – show file list - # 3. Called by ZLE itself – only should file list if prompt was empty + # 1. Called from `chpwd_functions` – show file list + # 2. Called by another ZLE plugin (like `dirhistory`) through `zle accept-line` – show file list + # 3. Called by ZLE itself – only should file list if prompt was empty + # Initialize only after setup is complete and only continue if enabled + if [[ $AUTO_LS_INIT_COMPLETE == false || $AUTO_LS_CHPWD == false ]]; then + return + fi + if ! zle \ || { [[ ${WIDGET} != accept-line ]] && [[ ${LASTWIDGET} != .accept-line ]] }\ || { [[ ${WIDGET} == accept-line ]] && [[ $#BUFFER -eq 0 ]] }; then @@ -44,7 +51,9 @@ auto-ls () { eval $cmd else # Otherwise run auto-ls function - auto-ls-$cmd + if [[ $BUFFER == cd\ * ]] || [[ $BUFFER == autojump\ * ]] || [[ $BUFFER == j\ * ]] || [[ $BUFFER == z\ * ]] || [[ $BUFFER == wd\ * ]] || [[ $BUFFER == fasd\ * ]]; then + auto-ls-$cmd + fi fi done zle && zle .accept-line @@ -58,7 +67,7 @@ auto-ls () { echo && zle redisplay elif [[ ${WIDGET} != accept-line ]] && [[ ${LASTWIDGET} == .accept-line ]]; then # Hack to make only 2 lines appear after `dirlist` navigation - # (Uses a VT100 escape sequence to move curser up one line…) + # (Uses a VT100 escape sequence to move curser up one line…) tput cuu 1 else zle .accept-line