I use ZSH with Oh My Zsh and I am trying to define a function called git
, as such:
function git() { echo "I'm happy because I am executed!" }
I have placed the function definition in $ZSH/custom/general.zsh
.
Everything else in this file works (I have a bunch of aliases there) except this function.
Running which git
outputs:
git () {
case $1 in
(commit|blame|add|log|rebase|merge) exec_scmb_expand_args "$_git_cmd" "$@" ;;
(checkout|diff|rm|reset) exec_scmb_expand_args --relative "$_git_cmd" "$@" ;;
(branch) _scmb_git_branch_shortcuts "${@:2}" ;;
(*) "$_git_cmd" "$@" ;;
esac
}
Removing git
from plugins=( ... )
didn't work. Trying to find this function in Oh My Zsh yielded no results.
I read the source code of oh-my-zsh.sh
, and it seems the custom
directory is loaded after all of OMZ's files, so it didn't make any sense to me, that when I placed my function at the bottom of .zshrc
it worked.
Any Ideas on how to keep the function in the custom
folder? I would like to keep things organized.
Best Answer
You probably installed
scm_breeze
, and my theory is that in your.zshrc
the sourcing ofscm_breeze.sh
is preceeded byoh-my-zsh.sh
. And if you put your git function definition at the very end of.zshrc
, then you probably exceed thescm_breeze.sh
, so that's the reason why it works.Try to move the line that sources
oh-my-zsh.sh
to the very end of your.zshrc
or at least in a position where it exceeds the sourcing ofscm_breeze.sh
. Restart zsh and see if it works. (alternatively you can removescm_breeze.sh
completely)If it still doesn't work, then back up your
.zshrc
and all youroh-my-zsh
stuffs, then create an empty.zshrc
, delete and reinstalloh-my-zsh
withcurl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
and then putfunction git() { echo "I'm happy because I am executed!" }
in$ZSH/custom/general.zs
, I have tested this, it worked for me. After that you can gradually reapply your former settings, step-by-step checking what exactly breaks your configuration.