Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Helper functions for adb. Offers a selection menu for multiple devices and makes logcat filtering easier.
#add to your .bash_profile / .bashrc
adbd () {
adb -s $(get_device) "$@"
}
function get_device() {
local devices=$(adb devices | grep device$)
if [ $(wc -l <<< "$devices") -eq 1 ]; then
awk {'print $1'} <<< "$devices"
else
IFS=$'\n' devices=($devices)
unset IFS
local device
PS3="Select a device # "
select device in "${devices[@]}"; do
if [ -n "$device" ]; then
awk {'print $1'} <<< "$device"
fi
break
done
fi
}
function logcat(){
local device
device=$(get_device)
if [ -z "$1" ]
then
adb -s $device logcat | coloredlogcat.py
else
local filters=""
for f in $@
do
export filters="$filters $f:*"
done
echo "filters $filters"
adb -s $device logcat $filters *:S | coloredlogcat.py
fi
}

These functions assume the following are in your $PATH

When you have more than once device or emulator connected it will offer a menu to select when device to use with adb.

Usage:

Invoke adb

adbd <command>

Invoke colored logcat

logcat <fliter1> <fliter2> <more filters>

save device-id to variable

deviceid=$(get_device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.