1

I use the bash terminal on Ubuntu Ubuntu 20.04.5 LTS, with the GNOME terminal emulator. When using the terminal, this is the current (default) behavior:

  1. When I open a new terminal session, it starts in ~.
  2. When I open a new terminal tab from a directory, say path/to/dir, the new tab starts in this directory path/to/dir.

I would like to change 1) without changing 2). I want to start a new terminal session from ~/start, but new tabs should still open in the current directory. How can I achieve this?

The otherwise perfect answer from this question (adding cd /start to .bashrc) does change 2) - with this, new tabs start in /start regardless of the current directory.

From comments at the same answer, I figure that the behavior "open a new tab" is not a bash function, but there must be some additional logic which makes "open a new tab" more than "open a new terminal". I assume that there is something going on in the terminal emulator which ensures the behavior specified at 2). But I am not even sure about that, and I would not know how to change it.

1

1 Answer 1

1

The shell and terminal do not really have a "default" start directory.

What they have is an inherited directory. The directory you start in is the directory the parent process was already in.

I can think of two ways to achieve your stated goal:

  • Add a shortcut that opens the terminal in ~/start or /start. You can create a start.desktop file or something that does this, and use this as your initial terminal.
  • If you never want to start in your home directory, you could add something to bashrc to detect that and change directories only if it starts in home. (However, I think adding a cd command to .bashrc is probably a bad idea long term.)
  • I think the idea (from the referenced alternate question) of using shell aliases to quickly change directories is a good one. Along the same lines is the shell CDPATH setting.

The "open in new tab" function is either a function of the graphical terminal, or a function of the graphical application you are clicking on. In general, bash is not a graphical application and knows nothing about any mouse or other GUI interactions or opening windows, etc. If opening a new tab in terminal inherits the start directory from the previous tab rather than the parent, then the shell is doing something clever to copy it from the bash in the previous tab.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .