From 1ba0af650ac575a7d35b10146d2e7a7b3b2e2ae6 Mon Sep 17 00:00:00 2001
From: Jacob Tomaw <jacob.tomaw@gmail.com>
Date: Tue, 19 Nov 2019 12:47:12 -0500
Subject: Use safer append to hook function arrays (#8406)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use add-zsh-hook to add functions to hooks. That way they won't be added again
when doing `source ~/.zshrc` multiple times.

Co-authored-by: Marc Cornellà <marc.cornella@live.com>
---
 lib/termsupport.zsh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'lib/termsupport.zsh')

diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index aa14f3f07..f5e367fcb 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -75,8 +75,9 @@ function omz_termsupport_preexec {
   title '$CMD' '%100>...>$LINE%<<'
 }
 
-precmd_functions+=(omz_termsupport_precmd)
-preexec_functions+=(omz_termsupport_preexec)
+autoload -U add-zsh-hook
+add-zsh-hook precmd omz_termsupport_precmd
+add-zsh-hook preexec omz_termsupport_preexec
 
 
 # Keep Apple Terminal.app's current working directory updated
@@ -99,7 +100,7 @@ if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
   }
 
   # Use a precmd hook instead of a chpwd hook to avoid contaminating output
-  precmd_functions+=(update_terminalapp_cwd)
+  add-zsh-hook precmd update_terminalapp_cwd
   # Run once to get initial cwd set
   update_terminalapp_cwd
 fi
-- 
cgit v1.2.3-70-g09d2