By tshepang

2010-11-08 09:17:21 8 Comments

After each login, there's certain commands that I run on specific tabs of gnome-terminal. This is a tedious process, so can this be done automatically?


@CesarDBA 2013-07-17 13:23:12

I am seeing here a lot of stuffs. Probably you do not need anything of this.

These are the steps that I did in my Oracle 5.9 Linux:

  1. Create a gnome-terminal icon in your Desktop.
  2. Open your gnome-terminal.
  3. Go to Edit -> Profiles.
  4. Select your Default profile and click on Edit.
  5. Go into "Title and Command" tab.
  6. Select "Run command as login shell" option.
  7. Click on Close button.

It worked for me. Of course, in my case, I just want to run .profile to setup my terminal environment.

@Gilles 'SO- stop being evil' 2010-11-08 21:53:25

You can start multiple commands on the same gnome-terminal command line by specifying the --tab-with-profile option multiple times, followed each time by a single -e specifying what command to run in that tab. You can also use --window-with-profile to have multiple windows. For example, the following command starts two windows with two tabs each; the first window runs bash in each tab, setting the environment variable TAB to 1 or 2; the second window runs htop in one tab and iotop in the other tab. The explicit sh invocation, with correct quoting, is necessary for some reason.

gnome-terminal --tab-with-profile="Default" -e 'sh -c '\''export TAB=1; exec bash'\' \
               --tab-with-profile="Default" -e 'sh -c '\''export TAB=2; exec bash'\' \
               --window-with-profile="Default" -e 'htop' \
               --tab-with-profile="Default" -e 'iotop'

If you want a command to run when you log in, put it in a shell script (for example ~/bin/my_gnome_login_commands, and register it in “System / Preferences / Startup Applications” in the Gnome menu. Alternatively, create a file ~/.config/autostart/my_commands.desktop containing

[Desktop Entry]

(You must use the full path to your home directory on the Exec= line, you can't use ~.)

(This answer has been tested with Gnome 2.30 on Ubuntu 10.04. As Gnome sometimes breaks compatibility, it may or may not apply to other versions.)

@Shawn J. Goff 2010-11-08 15:58:42

Yes, there is a way. You need to tell gnome-terminal to launch tabs with certain profiles; these profiles must be setup to start a shell with the commands you want.

First, you need to make a script (or a launcher icon) that will start gnome-terminal --tab-with-profile=Dev. "Dev" is the name of a profile you will create, so replace that with whatever you want it to be. Also, you can specify as many --tab-with-profiles as you want: it will open a tab for each.

Now, you need the profile you just referenced. This is created by opening gnome-terminal, and finding Edit->Profiles... in the menu. Make a new profile and give it the name you specified in the previous step. Next, you need to set its preferences. Highlight the newly created profile and click the Edit button. When the Profile Preferences dialog is up, activate the "Title and Command" tab, check "Run a custom command..." and in the associated textbox, put sh -c "ENV=$HOME/.dev_profile sh". Of course, you can set ENV to any path you want, as long as you are consistent in the next step. This starts sh, and sh will execute whatever commands are in $HOME/.dev_profile

Next, you need to create that shell profile file. So edit $HOME/.dev_profile (or whatever file you specified in the previous step). Place whatever commands you want in there; they will be executed when the shell is started. Treat this like you would a .bashrc - this will replace it. Depending on how your .bashrc is setup, you may want to source $HOME/.bashrc in the profile to copy all the functionality over from your normal sh profile.

@Shawn J. Goff 2010-11-08 19:00:07

By the way, I would highly recommend tmux or GNU Screen instead. They are terminal multiplexers that are a bit easier to setup for this kind of thing, and you can use them over an ssh connection. The only disadvantage is that they don't have tabs for you to click on, but you can get a menu list of windows or sessions that you can navigate up and down through and to switch to one. They also have other fancy options like split-screen, activity/inactivity monitors, and the ability to keep the session open without a terminal attached.

@Gilles 'SO- stop being evil' 2010-11-08 21:56:31

Screen has advantages, but it also has downsides. One is that scrolling back to past output is harder than with most X terminal emulators. Another is that you can't easily have two windows from the same screen session displayed at the same time (this is not a problem if you use separate screen sessions, but then you need to switch between them, which separate terminal emulator tabs or windows makes easier).

@Shawn J. Goff 2010-11-08 22:24:54

@Giles: Or Screen is easier to scroll: it depends on the way you like to work. I'm not sure what you mean about the two windows - I do it all the time: ^a S ^a <tab> ^a c

@Falmarri 2010-11-09 19:44:11

yes that is much simpler than double clicking the tab bar

@Shawn J. Goff 2010-11-09 22:55:03

@Falmarri: actually it is. I touch the mouse infrequently enough that the optical sensor turns itself off so I have to wave it around for about 1.5 seconds before I can click anything. (Not to mention it means moving my hand off the keyboard and having to find the home location on the keyboard again.)

@Trevor Boyd Smith 2011-09-15 16:02:01

What is a mouse? I've never heard of one. Where can I get one?

Related Questions

Sponsored Content

1 Answered Questions

Opening new gnome-terminal (v3.28+) with multiple tabs and different commands

1 Answered Questions

How can I run and monitor multiple commands, preferably with gnome-terminal?

1 Answered Questions

How are environment variables defined in a Gnome terminal session?

3 Answered Questions

[SOLVED] How can I launch gnome-terminal with unique titles for multiple tabs?

1 Answered Questions

[SOLVED] Gnome Terminal - button to run command

1 Answered Questions

[SOLVED] Launch web browser on Gnome startup

  • 2014-10-11 07:33:05
  • noname
  • 1392 View
  • 2 Score
  • 1 Answer
  • Tags:   gnome session

1 Answered Questions

[SOLVED] How to log user in to Gnome Desktop from remote ssh terminal?

  • 2012-02-21 16:19:44
  • malloc4k
  • 3410 View
  • 1 Score
  • 1 Answer
  • Tags:   linux gnome centos

2 Answered Questions

[SOLVED] run xmodmap commands after login

Sponsored Content