Created
June 14, 2012 05:23
-
-
Save sasagon/2928151 to your computer and use it in GitHub Desktop.
ディレクトリに出入りするとき、そこにあるスクリプトファイルを自動的にsourceで取り込む(.zshrc用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read .swenv.(out|in) when changing the current directory | |
function swenv_out() { | |
predir=~1 | |
outfile="${predir}/.swenv.out" | |
[ -d "$predir" -a -e "$outfile" -a -O "$outfile" -a -w "$outfile" ] && source $outfile | |
} | |
function swenv_in() { | |
infile=".swenv.in" | |
[ -e $infile -a -O $infile -a -w $infile ] && source $infile | |
} | |
function swenv_chpwd() { | |
swenv_out | |
swenv_in | |
} | |
setopt auto_pushd | |
typeset -ga chpwd_functions | |
chpwd_functions+=swenv_chpwd | |
swenv_in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes
Paste the code snippet in your .zshrc, and you can switch the shell settings automatically when you changing the current directory.
You can write the local (the directory only) settings in .swenv.in. If the file exists, your zsh reads it with source command when entering the directory.
And you also can write global settings in .swenv.out.
Your zsh will read it when leaving the directory.
If neither .swenv.in nor .swenv.out exists in the entering/leaving directories, your zsh does nothing.