Skip to content

Instantly share code, notes, and snippets.

@ricalo
Last active April 30, 2024 15:15
Show Gist options
  • Save ricalo/245bd396bd2e53d6a559 to your computer and use it in GitHub Desktop.
Save ricalo/245bd396bd2e53d6a559 to your computer and use it in GitHub Desktop.
Use git-bash from Android Studio terminal
if [ ! -z "${IDE}" -a "${IDE}" == "AndroidStudio" ]; then
cd $OLDPWD;
fi

I love Git for Windows. It's just easy to move between Linux, Mac and Windows if I use the same tools.

Today I was wondering, how can I use bash from the terminal in Android Studio?

I ran into a blog post that explains how to do the same thing with Cygwin.

Since the Cygwin and git for Windows are similar I decided to give it a shot. Here are the steps:

  1. Create Bash-AndroidStudio.bat included in this gist.

  2. @echo off
    set IDE=AndroidStudio
    "C:\Program Files\Git\bin\bash.exe"
    
  3. Add the following to your .bashrc file

  4. if [ ! -z "${IDE}" -a "${IDE}" == "AndroidStudio" ]; then
        cd $OLDPWD;
    fi
    
  5. In Android Studio, go to settings and add the path to your batch file in Tools > Terminal > Shell path.

Open a new terminal... voila!

@echo off
set IDE=AndroidStudio
"C:\Program Files\Git\bin\bash.exe"
@mochadwi
Copy link

first, why i can save my changes .bashrc?

You might want to access/open the git bash windows as administrator, then modify the bash.bashrc
Also don't forget to change this:

@echo off
    set IDE=AndroidStudio
    "go to your actual directory\folder\Git\bin\bash.exe"

second, where should i put the code?

In the last/beginning line of the .bashrc, e.g:

# this is the existing bash scripts
if [ ! -z "${IDE}" -a "${IDE}" == "AndroidStudio" ]; then
    cd $OLDPWD;
fi

@adesamp

@liang799
Copy link

liang799 commented Jan 9, 2022

Why is cd $OLDPWD not executed even though I followed all the steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment