3

I have created a custom gnome-terminal profile in Ubuntu 16.04 in order to setup a specific development environment. However I can't work out what to enter as the profile's custom command.

What I want my new terminal profile to do:

  1. Run whatever default scripts the default terminal usually runs (.bashrc etc)
  2. Run a custom script (eg $HOME/.dev_profile)

What should my custom command be?

  • You want that custom script to be ran automatically as soon as you open the terminal with the created profile? – M. Becerra Apr 25 '17 at 12:03
  • Yes. Instead of having to run source $HOME/.dev_profile manually in the default terminal, I want a terminal profile that runs it automatically. – Andrew Marshall Apr 25 '17 at 12:06
2

[NOTE: in the following, I've called the custom shell initialization file .devrc rather than .dev_profile to preserve the distinction between login and non-login shell initialization.]

Note also that this answer assumes that what you really want to do is source a custom environment rather than run a custom command.


One way to do this would be to create a custom initialization file (.devrc, say) that sources the standard files and then adds your customizations e.g.:

$ cat ~/.devrc
#
# Custom .bashrc for develeopment terminal profile
# 
if [ -r "/etc/bash.bashrc" ]; then
    . "/etc/bash.bashrc"
fi

if [ -r "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi

# add your dev-specific stuff here
export myvar1=foo
export myvar2=bar

Then in your gnome-terminal profile, you can set the Custom Command to use the alternate rc file

/bin/bash --rcfile "/home/steeldriver/.devrc"
0

You can simply create a .desktop file to open a terminal with the desired profile and run a script within such terminal.

The .desktop file:

[Desktop Entry]
Encoding=UTF-8
Name=Edit to add name
Exec=gnome-terminal -e --window-with-profile=PROFILENAME "source $HOME/.dev_profile"
Terminal=true
Type=Application
NoDisplay=true

Note that you can set on the profile settings whether you want the opened terminal to stay open or not, after the script has been completed.

  • Doesn't seem to work - at least if I replace source $HOME/.dev_profile with echo dev_profile I don't get anything in the new terminal. Is there no way to do this with the terminal profile's custom command setting? Changing the .desktop file requires me to log out/log back in again in order to test it. – Andrew Marshall Apr 25 '17 at 12:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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