Find the answer to your Linux question:
Results 1 to 2 of 2
I have a file called precmd in ~/.zfunctions that contains Code: echo "hello" My zshenv file should automatically autoload this for me, but it doesn't seem to be working. Why ...
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    53

    Problem loading functions in ZSH

    I have a file called precmd in ~/.zfunctions that contains
    Code:
    echo "hello"
    My zshenv file should automatically autoload this for me, but it doesn't seem to be working. Why is this? (~/.zshenv below)
    Code:
    ## set debug variables
    debug="echo"
    debug=":"
    
    ## set default zsh config directory
    export ZDOTDIR=$HOME
    
    ## source .zshrc if it exists
    if [[ -r $ZDOTDIR/.zshrc ]]; then
    	source $ZDOTDIR/.zshrc
    fi
    
    ## set env-ariables
    export PS1=$'%{\e[0;32m%}%U%n@%m%u:%~%(!.#.$)%{\e[0m%} '
    
    ## add ~/bin to path should it exist
    typeset -U path
    if [[ -d $HOME/bin ]]; then
    	path=($HOME/bin $path)
    fi
    
    ## add directories for custom functions
    typeset -U fpath
    fpath=(/etc/zsh/functions $ZDOTDIR/.zfunctions $fpath)
    
    ## autoload all the files in all the directories of fpath that are not empty
    $debug -e "\nlooping through dirs in fpath\n"
    for dir in $fpath; do
    	$debug -e "\nif dir isn't empty...\n"
    	if [[ $((`ls -a|wc -l` - 2)) -gt 0 ]]; then
    		$debug -e "\nautoload functions\n"
    		for func in `ls -a $dir`; do
    			[[ ! -d $dir/$func ]] && autoload $func && $debug "autoloading: $func"
    		done
    	fi
    done
    'precmd' gets printed yet I don't get a nice little 'hello' before every prompt why is this?

  2. #2
    Just Joined!
    Join Date
    May 2006
    Posts
    53
    Update:
    Ok, it is working. When I open the terminal the functions have been autoloaded and I get a nice little 'hello' before each prompt. Problem is if I change it to goodbye and type source ~/.zshenv nothing changes, but if I close the terminal and start a new one, it works. How do I fix this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...