# ZSH hooks
#
# $Revision: 2.3 $ $Date: 2019-01-30 01:17:03-05 $
# $UUID: 72ffa680-518c-5938-995f-d31b69a16c4f $
#
# Controls the use of the precmd, preexec and postcmd features;
# mostly used to log commands and set title bar when using X-windows.

case "$TERM" in
    xterm*|rxvt*)
        # Only need to do this when changing directories.
        function chpwd {
            local dir="${PWD}"
            local title="${LOGNAME}@${HOST}:$dir"
            print -n -D -P "\033]2;${title}\007"
            /bin/pwd >> ~/.cdlist.new

            # Check for a file called ".env" in the new directory, and
            # source it if found.  Saves a lot of time if you often switch
            # between projects.  "-G" makes sure the file is owned by your
            # effective group id.
            local _efile='./.env'
            test -f "$_efile" && test -G "$_efile" &&
                echo "sourcing $_efile" && source "$_efile"
        }
        ;;

    # Fix the keyboard if it's the console.
    at386) loadkeys /usr/share/lib/keytables/type_6/layout_36 ;;

    *)  ;;
esac

# Do this last, in case history is mangled.
fc -R $HISTFILE
