Looking at Your zsh Configuration Files

Your first step in modifying or adding zsh environment variables in your configuration files is to look at the configuration files, which show you the variables that are explicitly defined. As Code Listing 8.5 shows, you do this using more or the editor of your choice.

Remember that zsh configuration files exist in two places:

  • Systemwide configuration files (such as /etc/zprofile or /etc/zshenv)

  • Configuration files specific to your Unix account (such as ~/.zprofile or ~/.zshrc)

Code Listing 8.5. Your zsh configuration files set up your environment variables and other features of your Unix experience.
jdoe@sulley ~ $ more ~/.z* /etc/zl* /etc/zprofile /etc/zsh*
::::::::::::::
/home/jdoe/.zprofile
::::::::::::::
# /etc/zprofile and ~/.zprofile are run for login shells
#
::::::::::::::
/home/jdoe/.zshenv
::::::::::::::
export X11HOME=/usr/X11R6

if (( EUID == 0 )); then
     path=(/sbin /usr/sbin)
fi

typeset -U path
path=($path $X11HOME/bin /bin /usr/bin /usr/local/bin)
PATH=$PATH:/home/jdoe/scripts
::::::::::::::
/home/jdoe/.zshrc
::::::::::::::
# Reset prompts
PROMPT="%n@%m %3~ %(!.#.$) "    # default prompt
#RPROMPT=' %~'  # prompt for right side of screen


# bindkey -v# vi key bindings
bindkey -e    # emacs key bindings

if [[ ! -r ${ZDOTDIR:-$HOME}/.zshrc ]];then
    if  [[ -f /usr/share/zsh/$ZSH_VERSION/zshrc_default ]];then
    source /usr/share/zsh/$ZSH_VERSION/zshrc_default
    fi
fi
::::::::::::::
/etc/zlogin
::::::::::::::
# /etc/zlogin and .zlogin are sourced in login shells.

::::::::::::::
/etc/zlogout
::::::::::::::
# /etc/zlogout and ~/.zlogout are run when an interactive session ends
# clear
::::::::::::::
/etc/zprofile
::::::::::::::
#
::::::::::::::
/etc/zshenv
::::::::::::::
export X11HOME=/usr/X11R6

if (( EUID == 0 )); then
     path=(/sbin /usr/sbin)
fi

typeset -U path
path=($path $X11HOME/bin /bin /usr/bin /usr/local/bin)
::::::::::::::
/etc/zshrc
::::::::::::::

if [[ $(id -gn) = $USERNAME && $EUID -gt 14 ]]; then
    umask 002
else
    umask 022
fi
# Get keys working
if [[ $TERM = "linux" ]];then
     bindkey "^[[2~" yank
     bindkey "^[[3~" delete-char
     bindkey "^[[5~" up-line-or-history
     bindkey "^[[6~" down-line-or-history
     bindkey "^[[1~" beginning-of-line
     bindkey "^[[4~" end-of-line
elif [[ $TERM = "xterm" || $TERM = "rxvt"  ]];then
     bindkey "^[[2~" yank
     bindkey "^[[3~" delete-char
     bindkey "^[[5~" up-line-or-history
     bindkey "^[[6~" down-line-or-history
     bindkey "" beginning-of-line
     bindkey "" end-of-line
fi

# Set prompts
PROMPT="%n@%m %3~ %(!.#.$) "     # default prompt
#RPROMPT=' %~'    # prompt for right side of screen

# Some environment variables
path=($path $HOME/bin)
export HISTFILE=${HOME}/.bash_history
export HISTSIZE=1000
export SAVEHIST=1000
export USER=$USERNAME
export HOSTNAME=$HOST

# bindkey -v  # vi key bindings
bindkey -e    # emacs key bindings

for profile_func ( /etc/profile.d/*.sh ) source $profile_func

unset profile_func

# See comment at top.
if [[ ! -r ${ZDOTDIR:-$HOME}/.zshrc ]];then
    if  [[ -f /usr/share/zsh/$ZSH_VERSION/zshrc_default ]];then
    source /usr/share/zsh/$ZSH_VERSION/zshrc_default
    fi
fi
jdoe@sulley ~ $

To look at your zsh configuration files:

1.
more ~/.z* /etc/zl* /etc/zprofile
→ /etc/zsh*



At the shell prompt, type more followed by each of the possible system configuration filenames to view your configuration files. If you don’t have all (or any) of the files mentioned here, don’t worry. Just make note of the ones you do have. Code Listing 8.5 shows an example of what you might see.

2.
Write down, for your reference, the system configuration files and the order in which they’re run. (Remember, settings in the last file run override all previous ones.) Our system configuration files, all automatically called by the system, include

  • /etc/zshenv then ~/.zshenv
    
  • /etc/zprofile then ~/.zprofile
    
  • /etc/zshrc then ~/.zshrc
    
  • /etc/zlogin then ~/.zlogin
    
Keep in mind that the files you have may differ from the files that we have.

✓ Tips

  • Take special note of any lines in any of the files that end with a path and filename, or that reference other files directly, with something like /etc/profile on a line by itself. Each of those lines references another file that plays a role in getting you set up. Notice that some of the lines will reference others that don’t directly configure your environment.

    Some files include oddities like export HISTFILE=${HOME}/.bash_history line that reference the .bash_history file, containing the list of commands you’ve run. (Looks like a goof by the Linux distributor. Good thing you’re checking up on them, huh?)

  • You can use grep to make it easier to find the configuration files that set your path. grep –i path ~/.z* is a good way to start.

  • If you see something like path=($path $HOME/bin) in your configuration files, that’s okay. Just go ahead and use the syntax shown in this section on the following line anyway. It’s a feature of zsh that it understands about a bazillion different ways to express any single command.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset