1

I am working on software at a large corporation where I have little control over the overall technologies used, and as a result need to find solutions that will work within the constraints I have.

What I'm working on: I'm developing a UI that lets users launch konsoles with specific environments based on the projects they are working on. We currently have a command (let's call it "setContext") that users run in their konsole manually with a lot of arguments. setContext does a lot of work and sets a lot of environment variables. As part of my constraints, I have to use konsole, tcsh, and this setContext command. All my UI needs to do is compose the setContext command with the proper arguments, open a konsole, and run that command for the user, after what they will be in control.

The command I generate is something like:

konsole -e tcsh -c "setContext --someArgs"

This works, but closes the konsole right away. Using the --noclose option when launching the konsole keeps it open but not interactive.

The commonly accepted solution to this problem, is to append ;bash or ;$SHELL at the end of the command, in my case I have extrapolated it to be ;tcsh.

This is what is suggested in the following links, and many others:

This nearly works, as it does indeed keep the konsole open. In fact this is what I have been using for weeks without troubles, however we have noticed that running tcsh after setContext sources all the initialization files again (~/.cshrc, etc..), which resets some of the variables set by setContext.

This needs to work for hundreds of users, and I have no control over the cshrc files, so I need to find a way to keep the konsole open without sourcing these again. I tried tcsh -f but that doesn't preserve the environment.

I have been searching online all afternoon but haven't managed to find a solution. While I understand environments and commands okay, I am no expert and usually work in python. I am resorting to ask here because everything I'm finding is either a re-hash of the answer above, requires to modify cshrc files, or is way above my level and I can't decipher it.

Thanks in advance.

2 Answers 2

0

running tcsh after setContext sources all the initialization files again (~/.cshrc, etc..), which resets some of the variables set by setContext.

You could trick tcsh into not reading the ~/.cshrc by pointing the HOME environment variable to some other directory containing a .cshrc which resets HOME to its original value, sources the user's ~/.tcshrc or ~/.cshrc, and then calls your setContext.

Example, using /fake/home as the decoy home directory:

konsole -e sh -c 'REAL_HOME=$HOME HOME=/fake/home exec tcsh'

with /fake/home/.cshrc containing:

setenv HOME "$REAL_HOME"
if (-f ~/.tcshrc) then
   source ~/.tcshrc
else if (-f ~/.cshrc) then
   source ~/.cshrc
endif
setContext
# other aliases and initializations

Yes, this is a horrible kludge. Find something better ;-)

2
  • Thank you for your answer. I considered doing it this way, however other software that we are launching from that konsole will rely on the $HOME variable. One thing I thought about overnight is that I may be able to use setContext in a temporary .cshrc or something similar, so that I don't actually run the command, but somehow inject it into the start up of the konsole. EDIT: Oh I see what you did here, you set it back to the real home. Sadly I have no control over /etc/.cshrc Commented Oct 7, 2020 at 21:14
  • This is a good idea, thank you. In the meantime I found a possible alternative using qdbus to interface with konsole. I need a bit more time to ensure everything works as expected, and if it does I will post an alternate answer. I have upvoted yours but apparently votes by newbies do not show. Commented Oct 8, 2020 at 6:21
0

A possible workaround I'd like to share is somebody else is in the same situation as I am, is to use qdbus to send commands to another instance of konsole.

It's can be a bit convoluted because in my case I needed to know the Konsole's pid, but it did the trick.

I think I will still use user431397's method in the end because qdbus often gives a warning when sending commands, which could be removed by recompiling, but it's not something I can do, and the warning is annoying me.

I have also discovered yakuake while researching dbus, and it turned out to be installed here, and is easier to control with qdbus than konsole is.

You must log in to answer this question.

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