0

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 ". hat.sh" 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.

2 Answers 2

2

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"
2
  • 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, 2012 at 22:56
  • You could try to use sh -c "FOO=bar konsole" as the hotkey action.
    – mgorven
    Apr 25, 2012 at 23:06
0

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.sh $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.

You must log in to answer this question.

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