Skip to content
Advertisement

How to run linux command before starting up git bash terminal

I am working with Docker on my windows machine via git bash. Since git bash does not record the current status on closing, I need to set some environment variables related to Docker every time when I start a new terminal. The command I would like to run before start-up is:

eval $(docker-machine env)

Or better yet, have a bash script including other logics. For example if docker machine is not up, start the machine first, etc. Is there a way to automatically run bash command or script before opening a new git bash window?

Advertisement

Answer

I would recommend creating a new file under your home folder(~/) namely ~/.bashrc which is read by your terminal when it first starts-up. Add a function say myStartUpFunction() that runs your command as you need.

myStartUpFunction() {
    docker-machine env
}

myStartUpFunction

This would enable you to run the docker-machine env every time a new terminal session is opened.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement