Why is my .bash_profile breaking when a new "screen" session is made?

Viewed 176

New Terminal Window

New screen session

file : ~/.bash_profile (.bash_profile)

Whenever I create a new screen session on my Mac, the terminal window would display

bash: git_color: command not found
bash: git_branch: command not found

Why is the function git_color and git_branch is not getting executed on the screen session?

Is there any alternative to achieve it?

1 Answers

I am not entirely sure about how screen works.

What seems is that .bash_profile doesn't get executed as screen is not creating a login shell. [1]

Going by the general bash rules, PS1 is being read by the shell issued by screen because you exported it.

i.e., you did this:

export PS1

Do the same for your functions. [2]

Add 2 commands to your .bash_profile after you have defined both the functions:

export -f git_color
export -f git_branch

Alternatively, add those functions and PS1 to .bashrc as well.

[1] About .bash_profile and .bashrc

[2] Exporting functions

Related