4

When I open a new gnome terminal it loads zsh and puts me in my home directory (~). If I cd around and then press Ctrl+Shift+T it opens a new tab in the same directory as my last tab. I like this behaviour, but instead of starting in my home dir, I want to start in some other dir. How can I do this?

I can't put a cd command in ~/.zshrc because that will run when I open a new tab, and I can't put it in ~/.zprofile because that just doesn't run when I open a new terminal. So how do I do it?

mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • "I can't put it in ~/.zprofile because that just doesn't run when I open a new terminal." That's because you're not running `zsh` as a login shell. – 4ae1e1 May 31 '15 at 20:34
  • @4ae1e1 Just checked my /etc/passwd file; it's set to /bin/zsh. Don't "login" terminals run when you SSH into a system but not when you open a new terminal window? – mpen Jun 01 '15 at 15:33
  • `~/.zlogin` perhaps? – Don Bottstein Jun 01 '15 at 17:35
  • @Mark No, whether to use login shells is entirely up to you. It depends on what command is being run by your terminal emulator upon creating a new session. `zsh` alone runs an interactive, non-login shell; `zsh -l` runs an interactive, login shell. This can usually be customized in your terminal emulator profile/settings/preferences. It won't help for your particular use case (which I believe need some special interaction with the terminal emulator — for instance on OS X with iTerm2 I can solve this problem with a special profile, or AppleScript), but it's still one good thing to know. – 4ae1e1 Jun 01 '15 at 17:44
  • I just found [the option](http://i.stack.imgur.com/QQHax.png) to run zsh as a login shell, but it does this both when I open a new window and when I open a new tab. – mpen Jun 01 '15 at 18:01
  • @DonBottstein According to [this](http://unix.stackexchange.com/a/71258/45556) `.zprofile` runs before `.zshrc` and `.zlogin` runs after, but it's subject to the same problem. – mpen Jun 01 '15 at 18:04
  • @Mark Yeah, that's why I said "it won't help for your particular use case". This is not something you can do on the shell level; it really depends on your terminal emulator's features, and I can't comment on that because my terminal emulator is iTerm2 on OS X. (By the way, could you please mention me? I wouldn't see your comments if I didn't come back.) – 4ae1e1 Jun 02 '15 at 03:09
  • @mpen : You did not specify how you start the gnome teminal, but in any case, you can configure gnome to use a certain command for starting the shell. Using this, you could for instance specify something like `STARTDIR=/foo/bar zsh`, and inside .zshrc, **if** STARTDIR is set, do the `cd $STARTDIR` and then unset the variable (so that the cd does not happen again, when you open a subshell subsequently). – user1934428 Aug 23 '21 at 08:17
  • @user1934428 Good point.. I could edit my taskbar icon to add some flags. I do all my work over ssh now though, so this sol'n worked https://stackoverflow.com/a/54242698/65387 – mpen Aug 24 '21 at 00:50

0 Answers0