Protip: Bash Autocomplete for Android ADB
Jesse Chen • February 17, 2012 • 2 min read
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.
- 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 ~/.bashrcto 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. :)
© 2021, Jesse Chen • 95e966e