Skip to content

Instantly share code, notes, and snippets.

@Darkside73
Created July 24, 2014 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darkside73/046c3b69a726678d07eb to your computer and use it in GitHub Desktop.
Save Darkside73/046c3b69a726678d07eb to your computer and use it in GitHub Desktop.
Oh-my-zsh: alias rails, rake commands to generated spring binstubs on entering project's directory
# put this file to $HOME/.oh-my-zsh/custom/plugins/chpwd_profiles
# and add plugin name to .zshrc: plugins=(... chpwd_profiles)
function chpwd_profiles() {
local -x profile
zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
if (( ${+functions[chpwd_profile_$profile]} )) ; then
chpwd_profile_${profile}
fi
CHPWD_PROFILE="${profile}"
return 0
}
chpwd_functions=( ${chpwd_functions} chpwd_profiles )
# put this file to $HOME/.oh-my-zsh/custom
# projects profile for projects directory and subdirectories where can be located rails projects
zstyle ":chpwd:profiles:$HOME/projects(|/|/*)" profile projects
# actually call the function
chpwd_profiles
# Executed when entering the profile
chpwd_profile_projects()
{
alias_rails_binstub rails
alias_rails_binstub rake
}
# Execute when leaving the profile
chpwd_leave_profile_projects()
{
alias rails="rails"
alias rake="rake"
}
function alias_rails_binstub ()
{
if [ -f $PWD/bin/$1 ]; then
alias $1="$PWD/bin/$1"
else
alias $1="$1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment