Friday, June 23, 2017

command line - Run .bashrc only if terminal launched from within GUI

Some of the similar questions don't quite seem to match with my question. What I'm trying to do is to have .bashrc (or similar) to only run certain custom commands when I launch it from within the GUI (Xfce), but not in the initial login screen.


Some details:



  • Ubuntu 16.04 Virtual Machine (VirtualBox 5.2.10) on Windows host

  • When I launch it, I use the user vagrant in the boot login screen

  • I normally launch Xfce manually with sudo startxfce4

  • Then once the GUI has loaded, I launch a terminal (Terminator) and it runs for user vagrant


So what currently happens:



  1. I launch the VM

  2. It asks for user in the boot screen

  3. Then it will use the .bashrc of that user and already does the commands I have there. I would want them to only run when I use the GUI terminal (This is my question - how to do that?)

  4. Start the GUI

  5. Then when I launch the terminal in the GUI, it will run those same commands again.


What I would like to happen:



  1. Launch the VM

  2. Login as the user - and do not run the specified commands yet

  3. Start the GUI

  4. Launch the terminal from GUI - now it should run the commands automatically


So, basically I'm looking for some kind of system flag that tells it is not running on GUI. Does such exist? I imagine you could check it from somewhere, like xfce status or similar?


The key thing is, I would like it to run automatically instead of running a script from PATH, because that is easy to forget and you might spend quite some time debugging why something doesn't work, only to notice you forgot to run the prerequisite commands.


Thanks!

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...