Linux (basics) - How to use conditional on command in bashrc depending how terminal is spawned?

0

I am using Guake Terminal in Ubuntu.

I have added the following line to my bashrc:

guake -e "cd /home/jasoons/Documents/Termainal" -r launch

This opens a tab called 'launch' in that directory where I'll put useful scripts. Some of these scripts I will use to configure the tabs of Guake or anything else based on what I want to work on; as detailed here.

The issue is that if one of these script opens a new Guake tab in a specific directory, then that line in the bashrc overwrites whatever directory I wanted to open in.

A solution I have in mind is of the form:

#in bashrc
if [USE SOME CONDITIONAL]; then
guake -e "cd /home/jasoons/Documents/Termainal" -r launch
fi

#in script
guake -n /home/jasoons/Desktop/Programming/ -r "ownComp" -e "SET SOME CONDITIONAL"

How can 'USE SOME CONDITIONAL' and 'SET SOME CONDITIONAL' be filled in to avoid this issue?

Any other suggestions? Is this an appropriate line of thought to solve this issue?

JasoonS

Posted 2016-09-09T12:57:57.723

Reputation: 109

What is your question? – AFH – 2016-09-09T13:16:51.620

What is a way to fill in 'USE SOME CONDITIONAL' and 'SET SOME CONDITIONAL' in those scripts such that the one in the the baschrc doesn't run when it shouldn't? – JasoonS – 2016-09-09T13:19:14.767

Or of course, I am asking for any suggestions on how to solve this issue. – JasoonS – 2016-09-09T13:21:00.353

1Instead of just down-voting could you please explain your issue? Do you not understand the problem I am trying to solve? Do you think it is too trivial to be asked on this site? Do you think it is not relevant to be asked on this site? – JasoonS – 2016-09-09T13:26:50.450

1export PATH="/home/jasoons/Documents/Termainal:$PATH" – Ipor Sircer – 2016-09-09T13:53:35.387

1I neither up- nor down-voted, but I still find your question confusing: do you need to know about the commands export KEEP_WD=y and [ -z "KEEP_WD" ]? – AFH – 2016-09-09T14:49:17.367

Answers

1

You need to use an environment variable, such as KEEP_WD, which should be exported to ensure that it will be passed to whichever shell incarnation runs .bashrc. Your commands then become:-

In .bashrc:

if [ -z "$KEEP_WD" ]; then
    guake -e "cd /home/jasoons/Documents/Termainal" -r launch
fi

In script:

guake -n /home/jasoons/Desktop/Programming/ -r "ownComp" -e "export KEEP_WD=y"

AFH

Posted 2016-09-09T12:57:57.723

Reputation: 15 470