Skip to main content
The 2024 Developer Survey results are live! See the results
added 1074 characters in body
Source Link

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.

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?

Thanks!

*This is my first Question at stackxchange.com, so please don't be too rough.

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.

Source Link

Why do I have to use this command twice to execute it?

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?

Thanks!

*This is my first Question at stackxchange.com, so please don't be too rough.