Score:2

gnome-terminal: how do you set working-directory?

sa flag
QF0

This has been bugging me for years. The terminal starts up in~/Desktop (up to 20.04, anyway), which is completely useless. How do I fix this? What I know so far:

  1. It doesn't start in the current directory, so any changes to .bashrc/etc won't help. ~/Desktop behaves almost as if it's compiled into the app
  2. There are no dconf settings (/org/gnome/terminal/legacy/profiles) related to setting working-directory
  3. You can't set in the profile for a given terminal
  4. You can't set it by editing the Exec string in /usr/share/applications/org.gnome.Terminal.desktop - it doesn't work

If you already have a terminal open, then this does work:

$ gnome-terminal --working-directory=$HOME

But if you change any/all of the Exec strings in /usr/share/applications/org.gnome.Terminal.desktop, it makes no difference:

Exec=gnome-terminal --working-directory=$HOME

This last one is known to work in RHEL.

Update:

  1. A desktop icon starts up in my home directory, when there is no working-directory in the Exec setting

  2. CTL-ALT-t starts up in my home dir, presumably using the global settings in /usr/share/applications/org.gnome.Terminal.desktop

  3. Desktop right-click always starts up in ~/Desktop, per vanadium's comment

  4. update-alternatives output is

    $ update-alternatives --display x-terminal-emulator x-terminal-emulator - auto mode link best version is /usr/bin/gnome-terminal.wrapper link currently points to /usr/bin/gnome-terminal.wrapper link x-terminal-emulator is /usr/bin/x-terminal-emulator slave x-terminal-emulator.1.gz is /usr/share/man/man1/x-terminal-emulator.1.gz /usr/bin/gnome-terminal.wrapper - priority 40 slave x-terminal-emulator.1.gz: /usr/share/man/man1/gnome-terminal.1.gz

vanadium avatar
cn flag
See my answer, but still it would be good to specify in detail how you start up the terminal (right-click on desktop? From an icon on the desktop? Using a shortcut key?). That it opens in the Desktop directory by default is rather unusual and will depend on how you start it up. Right-click on the desktop opens it in that folder by design.
QF0 avatar
sa flag
QF0
@vanadium: interesting - right-click, `Open in terminal`, fails. CTL-ALT-T, works! I always use a panel icon in RHEL - I'll give that a go.
nobody avatar
gh flag
What gives `update-alternatives --display x-terminal-emulator` can you add this to your question please?
nobody avatar
gh flag
Maybe a problem in the wrapper skript? gnome-terminal is "called" over this perlsktrpt and get the option from there.
Score:3
cn flag

It will work if you explicitly spell out the directory instead of specifying $HOME. Reason: desktop launchers do not support bash variables or bash expansions.

QF0 avatar
sa flag
QF0
I replaced `$HOME` with `/home/myname` in all 3 occurrences of the `Exec` setting in `/usr/share/applications/org.gnome.Terminal.desktop`, but unfortunately it made no difference, even after a logout. Same result when running direct on a laptop or over vnc. But surely this can't be right, because there's then no way to specify per-user directories?
QF0 avatar
sa flag
QF0
Yes, your comment was enough - CTL-ALT-T does the job, and my new icon works as well, so no problem left. You may well be right about the explicit path, but I think you may have found the magic *desktop* `.desktop` file, rather than the `/usr/share/applications` version, so +1 for effort :)
QF0 avatar
sa flag
QF0
Because it doesn't actually work (for me, anyway) on right-click, which is what I was (previously) doing: using a full path doesn't help (see my first comment). Maybe it's working for you because you're using a different `.desktop` file, which is what I was trying to say in the last comment. I'm inclined to believe that the terminal produced by right-click on the desktop is *hard-wired* to start up in `~/Desktop`, as per @egmont's reply, and stuff I've seen on the net about KDE's approach to this.
vanadium avatar
cn flag
Fair enough. I guess I do not really grasp what the question really is about.
Score:0
cn flag

If you right-click on the desktop, the menu you'll get is the desktop's menu. It'll have entries such as "New Folder" creating a new folder on the desktop. It also has an entry called "Open in Terminal" (notice the word "in"!), which opens the terminal in the Desktop directory, or actually using the menu entry's logic I should rather say it opens the Desktop directory in a terminal.

I personally agree with you in that I find this a pretty useless feature, so I never use this menu entry. I personally use either the global shortcut Ctrl+Alt+T, or click on the icon in the dock / launcher (whatever it's called), this latter method having the advantage that I can start up the terminal the same way as I'd start up my other favorite and frequently used applications.

Note that it has nothing to do with GNOME Terminal, it's all about the Desktop. If you change your preferred terminal to something else, the desktop's "Open in Terminal" menu will open that one in that folder. No wonder that you didn't find any options about the working directory in GNOME Terminal's settings, indeed there aren't any, it's absolutely not GNOME Terminal's decision to open in that folder.

My personal recommendation is to avoid using that menu entry which, by questionable design, intends to open a terminal in the Desktop directory. That being said, finding the right .desktop file and adding the --working-directory flag to gnome-terminal should also work, as per vanadium's comments. Yet another possibility is to fix up the directory from .bashrc.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.