public
Last active

Helper functions for adb. Offers a selection menu for multiple devices and makes logcat filtering easier.

  • Download Gist
.bashrc
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#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
}
bashrc.md
Markdown

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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.