I made an alias alias goto="cd $@ && source ~/.zshrc"
and it works, but only if I execute it twice. Even after I execute it twice in one shell, and if I want to move to another dir, I must again execute it twice. Why is that and how can I change that?
I need to type two times goto <dir>
. The first time, I am still in the normal dir and the second time, I got to my destination. I need to source .zshrc, because I have a check for the path:
CURRENT=$PWD
AT_HOME=0
AT_ROOT=0
if [ $PWD = $HOME ]; then
AT_HOME=1
elif [ $PWD = / ]; then
AT_ROOT=1
else
cd ../
if [ $PWD = $HOME ]; then
AT_HOME=1
elif [ $PWD = / ]; then
AT_ROOT=1
else
cd ../
if [ $PWD = $HOME ]; then
AT_HOME=1
elif [ $PWD = / ]; then
AT_ROOT=1
fi
fi
fi
cd $CURRENT
if [ $AT_HOME = 0 ]; then
if [ $AT_ROOT = 0 ]; then
ZSH_THEME="prompt-basename"
else
ZSH_THEME="prompt-normal"
fi
else
ZSH_THEME="prompt-normal"
fi
And it gives me full path (even at /usr/lib/jvm/java-13/bin) and when I source ~/.zshrc, it gives me the path I want (.../java-13/bin). By the way, replacing &&
with ;
does not work neither.
Thanks!
*This is my first Question at stackxchange.com, so please don't be too rough.
~/.zshrc
? Something in there might be tripping up zsh's alias system? Maybe if you edit your question to state what you are trying to do with the alias, someone who knows a cleaner and efficient way to do so will contribute an answer?goto
or thealias
command? While I can assume the most likely answers to these questions, it's better that you clarify them.$@
isn't what you think it is there.;
instead of&&
? If so, thencd
's exit status is not 0, which means it failed.