Gnome Terminal Custom Commands


A Fedora newbie here.

I think it would be best if I could describe the desired outcome before talking about problems I’m running into here. To start, I’m using Fedora 33 and the included terminal app (gnome-terminal) with the zsh shell. What I would like is when I click on the Terminal icon in the launcher that a terminal opens with 3 tabs, the first in “~”, the second in “~/SomeDir/SomeOtherDir”, and the third in “~/SomeDir/SomeThirdDir”. Ideally, I’d actually like 4 different windows to open up with different tabs in each doing different things (i.e. running a frontend server, a backend-api, etc), but let’s stick to “more simple” now.

I’ve set two aliases in my ~/.oh-my-zsh/custom/aslias.zsh file called alias_1 and alias_2, which, when using the terminal with cd me into the correct directory. So how do I get gnome-terminal to open a window with three tabs two which run an alias that will move me to the desired directory?

I’ve tried setting up the Default profile in Preferences to run the command, but it either doesn’t recognize the alias or errors out some other way.

Thanks for your help.

gnome-terminal -q \
--window -t "top" -e "top" \
--tab -t "free" -e "watch free -m" \
--tab -t "swap" -e "watch swapon -s" \
--window -t "journal" -e "journalctl -f" \
--tab -t "shell"

I’m not sure I understand what this means.

So, if I try gnome-terminal -q --window -e "alias_1" I will get an error saying “failed to execute child process ‘alias_1’:Failed to execve: No such file or directory”. From one terminal, I can run gnome-terminal --window --working-directory "/home/me/SomeDir", which is OK. But it’d be awesome if I could have that command run when I click the icon, so I’ve been trying work with the Profiles for gnome-terminal which has a command tab. But I’m not sure how I need to set up that tab to make it do what I want.

Does this make sense?

Apparently you cannot use aliases in this case.
Use commands from PATH, or specify full paths to custom scripts.
You can create those in ${HOME}/.local/bin for example.

What about something like:

cp /usr/share/applications/org.gnome.Terminal.desktop ~/.local/share/applications/custom-terminal.desktop
sed -i 's/^Name=Terminal$/Name=Custom Terminal/' ~/.local/share/applications/custom-terminal.desktop
sed -i 's/^Exec=gnome-terminal$/Exec=gnome-terminal --window --working-directory "/home/me/SomeDir"/' ~/.local/share/applications/custom-terminal.desktop
update-desktop-database ~/.local/share/applications

Would that give you the custom launcher that you need?

1 Like

I’m not exactly sure what those do.

I mean, I can do a workaround by using an alias that uses the gnome-terminal --window --tab ... stuff. But what is the Commands tab in Preference supposed to do. What does “run command as login shell” mean or “run a custom command instead of my shell”? Why if I select “run a command as a login shell” do I not get to enter a command to run? Why are these “help” pages so obtuse? Terminal

The help file says that “The command will be passed to the terminal exactly as you write it, including any arguments that you specify” but that’s not what happens. Putting cd ~/Whatever in that box returns an error.

You are replacing the current shell with a custom command.
But you need a shell to expand special characters like tilde and process commands afterwards.

1 Like

Passing sh -c 'cd ~/Documents' opens a window with a message saying “the child process exited normally with status 0” and button that says “Relaunch.”

gnome-terminal -q -e "sh -c 'cd $(xdg-user-dir DOCUMENTS); ${SHELL:-sh}'"
1 Like