From ad7c4bae9781483a15c2a11c9db247edf7c3c365 Mon Sep 17 00:00:00 2001
From: "martin f. krafft" <madduck@madduck.net>
Date: Sat, 17 May 2008 12:30:33 +0100
Subject: [PATCH] set warn_create_global and unglobal a few

---
 .zsh/func/vcsh          |  4 ++--
 .zsh/zshrc/00_varsetup  |  3 +++
 .zsh/zshrc/30_aliases   |  5 ++---
 .zsh/zshrc/60_vcsprompt |  3 +--
 .zsh/zshrc/80_history   |  3 ++-
 .zsh/zshrc/80_prompt    | 10 +++-------
 .zsh/zshrc/99_TODO      |  3 ++-
 7 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/.zsh/func/vcsh b/.zsh/func/vcsh
index ca26a9e..0a08b5e 100755
--- a/.zsh/func/vcsh
+++ b/.zsh/func/vcsh
@@ -10,7 +10,7 @@
 # Source repository: http://git.madduck.net/v/etc/zsh.git
 #
 
-FGIT_BASE="$HOME/.fgits"
+local FGIT_BASE="$HOME/.fgits"
 
 if [ "${1:---help}" = '--help' ] || [ $# -gt 1 ]; then
   echo "usage: ${0%/*} reponame" >&2
@@ -32,7 +32,7 @@ if [ ! -d "$FGIT_BASE/${1}.git" ]; then
 fi
 
 export GIT_DIR="$FGIT_BASE/${1}.git"
-_WORKTREE="$(git config --get core.worktree)"
+local _WORKTREE="$(git config --get core.worktree)"
 export GIT_WORK_TREE="$(readlink -f $GIT_DIR/$_WORKTREE)"
 unset _WORKTREE
 
diff --git a/.zsh/zshrc/00_varsetup b/.zsh/zshrc/00_varsetup
index 68ec386..a49f67d 100644
--- a/.zsh/zshrc/00_varsetup
+++ b/.zsh/zshrc/00_varsetup
@@ -16,4 +16,7 @@ typeset -ga preexec_functions
 typeset -ga precmd_functions
 typeset -ga chpwd_functions
 
+# warn on accidental creation of global variables
+setopt warn_create_global
+
 # vim:ft=zsh
diff --git a/.zsh/zshrc/30_aliases b/.zsh/zshrc/30_aliases
index 82625ff..562f4b9 100644
--- a/.zsh/zshrc/30_aliases
+++ b/.zsh/zshrc/30_aliases
@@ -23,12 +23,11 @@ alias curl='noglob curl'
 alias apt-cache='noglob apt-cache'
 alias locate='noglob locate'
 
-_ls_opts=(-bC --color=auto)
-ls --group-directories-first >/dev/null 2>&1 \
+typeset -a _ls_opts; _ls_opts=(-bC --color=auto)
+command ls --group-directories-first >/dev/null 2>&1 \
   && _ls_opts+=--group-directories-first
 # I prefer POSIX collation for ls
 alias ls="LC_COLLATE=POSIX ls $_ls_opts"
-unset _ls_opts
 
 alias ll='ls -l'
 alias l=ll
diff --git a/.zsh/zshrc/60_vcsprompt b/.zsh/zshrc/60_vcsprompt
index 4cc18a3..9fa0f44 100644
--- a/.zsh/zshrc/60_vcsprompt
+++ b/.zsh/zshrc/60_vcsprompt
@@ -144,9 +144,8 @@ __vcs_set_prompt_variables()
       if [ -d "$GIT_DIR" ]; then
         # poor man's replace until I find out how to do named dirs properly
         # here:
-        _D="${GIT_DIR/$HOME/~}"
+        local _D="${GIT_DIR/$HOME/~}"
         set -- "$_D" "$2" "${${1#$_D}%/}"
-        unset _D
       fi
       ;;
     hg)
diff --git a/.zsh/zshrc/80_history b/.zsh/zshrc/80_history
index 4a80f06..af0f93b 100644
--- a/.zsh/zshrc/80_history
+++ b/.zsh/zshrc/80_history
@@ -8,7 +8,8 @@
 # Source repository: http://git.madduck.net/v/etc/zsh.git
 #
 
-HISTFILE=$ZVARDIR/history
+# typeset -g on this one to make warn_create_global happy
+typeset -g HISTFILE=$ZVARDIR/history
 HISTSIZE=10000
 SAVEHIST=$HISTSIZE
 LISTMAX=1000
diff --git a/.zsh/zshrc/80_prompt b/.zsh/zshrc/80_prompt
index a2b18eb..54d0e4d 100644
--- a/.zsh/zshrc/80_prompt
+++ b/.zsh/zshrc/80_prompt
@@ -9,20 +9,16 @@
 #
 
 if [ "${PS1:-}" = '%m%# ' ]; then
-  _MIDDLE="%1v%(2v.|%B%2v%b|.)%(3v.%3v.)"
+  local _MIDDLE="%1v%(2v.|%B%2v%b|.)%(3v.%3v.)"
   if is_root; then
     _MIDDLE="%25<..<%~%<<"
-    _PS1_HL=U
+    local _PS1_HL=U
   fi
 
-  _MACHINE_NAME="${_PS1_HL:=B}%m%${(L)_PS1_HL}"
+  local _MACHINE_NAME="${_PS1_HL:=B}%m%${(L)_PS1_HL}"
   _MACHINE_NAME="$_MACHINE_NAME${debian_chroot:+/%S$debian_chroot%s}"
 
   PS1="%(2L.+.)%${_MACHINE_NAME}:${_MIDDLE}%# "
-
-  unset _MACHINE_NAME
-  unset _PS1_HL
-  unset _MIDDLE
 fi
 
 : ${RPS1:="#%(0?..%?,)%!"}
diff --git a/.zsh/zshrc/99_TODO b/.zsh/zshrc/99_TODO
index 4fbaa92..7d6536b 100644
--- a/.zsh/zshrc/99_TODO
+++ b/.zsh/zshrc/99_TODO
@@ -56,7 +56,8 @@ setopt c_bases
 WORDCHARS="${WORDCHARS//\/}"
 
 # report time stats when command takes longer than 5 seconds
-REPORTTIME=5
+# typeset -g to make warn_create_global happy
+typeset -g REPORTTIME=5
 
 MAILCHECK=0
 
-- 
2.39.5