Change directory depending on start directory zsh

5,584

Thanks to QuickishFM I found the solution. I saw in an other stack post if [[ "${pwd}" == "/mnt/c/Windows/System32" ]] ... fi but that did work. After some research i found the solution.

if [[ $(pwd) == /mnt/c/Windows/System32  ]]
then
    cd ~
fi

Thanks

Share:
5,584

Related videos on Youtube

Lira
Author by

Lira

Updated on September 18, 2022

Comments

  • Lira
    Lira over 1 year

    I am using the new Windows 10 terminal with the WSL ubuntu and zsh (oh-my-zsh) shell as the standard terminal inside. It is configured that the context menu (right-click) has the option "open terminal here". It will open the new terminal with the Ubuntu and zsh shell in the directory I called it from. It works perfectly but now when I open the terminal via the start menu the start directory is /mnt/c/Windows/System32.

    I want that on start-up of the terminal the directory changes to the home directory if it would start in /mnt/c/Windows/System32.

    How can I do that? How do I know in which directory zsh will start?

    • QuickishFM
      QuickishFM over 4 years
      You could run a command at startup every time, that checks if pwd returns /mnt/c/WIndows/System32, and if so, then it cds into ~. Perhaps theres a way to do this in the zsh configuration file like you can do for .bashrc, for example. I only use Bash for now so I'm unsure how to implement it straight up - but this should get you on the right track.