INVISIBLE HEADING 1

Protip: Bash Autocomplete for Android ADB

February 17, 2012 3:00 pm by
bash autocomplete for adb

Introduction

This is a super quick tip that will only take 1 minute to make your android development so much easier.  Android Debug Bridge (adb) is a command-line tool that lets you interface with an emulator or an android device.  Its great and previously I wrote about how you can debug your Android app wirelessly on your device.  What sucks though is that you can’t tab autocomplete commands (e.g. type ‘adb d’ then tab and bash will autocomplete and fill out ‘adb devices’), which means having to look up adb commands to figure out what you want and/or wasting time by typing the whole command (every ms counts!).

This protip will get you setup with bash autocomplete for ADB in less than 1 minute.  Ready?  Here we go.

Instructions

  • Download the adb bash completion file here from Roman’s repo.  Another good one is here on github by mbrubeck.
  • Store the file somewhere safe.  Anywhere you want. I chose /bin.
  • Use your favorite editor of choice (which should be vim) to edit your ~/.bashrc file.
  • Add the following lines (substitute your own path to the adb bash completion file) to the end of your ~/.bashrc file:
if [ -e /bin/adb.txt ] ; then
     source /bin/adb.txt
fi
  • Save and quit.  In your terminal, type source ~/.bashrc to reload your bash.
  • Check if it works.  Type ‘adb d’ and press tab to see if it autocompletes to ‘adb devices’.

And that’s it!  I’ve been looking for something like this for a long time.  Hope it helps you as much as it did for me. :)

Tags: , , , ,

About

Jesse is a software engineer at Facebook, who just graduated from UC Berkeley. Passionate about mobile technology and entrepreneurship, he started his own blog as a home for his tutorials, projects, and random thoughts. Follow him on Facebook to stay updated on his latest tutorials and projects.