-
Notifications
You must be signed in to change notification settings - Fork 23
/
device
executable file
·55 lines (50 loc) · 1.04 KB
/
device
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
CONFIG_FILE=".device.config"
if [ -f "$CONFIG_FILE" ]; then
source $CONFIG_FILE
fi
case $1 in
"")
echo Selected device \"$ANDROID_SERIAL\"
exit 0
;;
add)
echo "$2=$3">>$CONFIG_FILE
;;
*h|*help)
cat <<TEXT
Device helper
A simple wrapper to dive devices alias
usage:
$0 add <alias> <serial>
- Add device to a alias list
$0 <alias> <command>
- run command on given device
$0 h
$0 help
- Show this message
TEXT
;;
all)
lines=$(adb devices | tail --lines=+2)
IFS=$'\n'
for line in $lines ; do
if [[ "$line" == *"no permissions"* ]] || [[ "$line" == *"offline"* ]]; then
continue
fi
split=($(echo $line | grep -Po "[^\s]+"))
export ANDROID_SERIAL=$split
${@:2} &
done
;;
*)
set +e
ANDROID_SERIAL=$(eval echo \${$1} 2>&1 > /dev/null)
if [ "$?" != "0" ] || [ -z "$ANDROID_SERIAL" ]; then
ANDROID_SERIAL=$1
fi
export ANDROID_SERIAL
${@:2}
# echo " Serial \"$ANDROID_SERIAL\""
# echo "Command \"${@:2}\""
esac