Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of different "hats" on my computer, including multiple on-the-go projects (e.g., $work, a few projects on github, some on Sourceforge, some I'm involved with, some I just follow, etc.). Each one has its own pseudo-home directory (e.g., ~/hat/$projectname). Some have their own specific environment settings (e.g., DB2 instance environment).

So, I have a shell tool to switch from one to another ("hat $projectname"). It finds the correct home directory, cd's to it ("hat" is an alias for "." so I can do this), sets up the environment, etc. Because I'm lazy.

Now I want to get a bit more lazy. I'd like to set up a hotkey to launch konsole with the correct parameters for the one hat I wear the most: $work. I'd like to effectively pre-type "hat work" into the window. But I'm not at all sure how to pass this through konsole to bash to my .profile (?) and leave the shell running afterward. All while not doing any of this for the hotkey I already have that launches konsole normally.

share|improve this question

Konsole and the shell it executes will inherit any environment variables set when Konsole is executed. The following command (which you could put in a script and assign a hotkey to) will result in the FOO variable being set in the shell:

$ FOO=bar konsole

The other option is to create different startup scripts for your shell (I'm assuming bash below), and modify the command which Konsole executes:

$ konsole -e "bash --rcfile ~/.bashrc-$projectname"
share|improve this answer
While the first one looks like it works, when you put it into the custom hot keys for KDE, it doesn't work (it's not run by the shell). The second is annoying in that I have to have an extra .bashrc file for each project I want to create a hotkey for, though I don't see a significantly better option, thanks. – Tanktalus Apr 25 '12 at 22:56
You could try to use sh -c "FOO=bar konsole" as the hotkey action. – mgorven Apr 25 '12 at 23:06
up vote 0 down vote accepted

What I ended up doing is creating a new profile for Konsole, "Work". And I have it set to run the same as normal, but it can set specific environment variables, so I told it to set HAT_PROJECT=work as an additional environment variable. Then at the bottom of my .bashrc, I simply run ". $HAT_PROJECT" if it is set, and also unset it so it doesn't survive.

This is not significantly different from mgorvan's second option as it does end up creating a bunch of extra cruft I was hoping to avoid.

Thanks to #kde on IRC for why the first option didn't work.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .