Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
3  
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. –  Shawn J. Goff Nov 8 '10 at 19:00
1  
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). –  Gilles Nov 8 '10 at 21:56
    
@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 –  Shawn J. Goff Nov 8 '10 at 22:24
1  
yes that is much simpler than double clicking the tab bar –  Falmarri Nov 9 '10 at 19:44
2  
@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.) –  Shawn J. Goff Nov 9 '10 at 22:55

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]
Type=Application
Exec=/home/tshepang/bin/my_gnome_login_commands
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true

(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.)

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.