Skip to content

Instantly share code, notes, and snippets.

@atomofiron
Created April 20, 2023 23:54
Show Gist options
  • Save atomofiron/dfbd6d119e69a4d2fa26ca96556a2adc to your computer and use it in GitHub Desktop.
Save atomofiron/dfbd6d119e69a4d2fa26ca96556a2adc to your computer and use it in GitHub Desktop.
#!/bin/sh
adbpath=$(which adb)
if [ -f $adbpath ]; then
alias adb='adbrun'
fi
adbs() { # adb / adb -s ...
devices=$($adbpath devices | grep -Po '.+(?=\tdevice)')
# make an array
devices=( $devices )
if [[ ${#devices[@]} < 2 ]]; then
printf $adbpath
return
fi
for i in "${!devices[@]}"; do
printf "$i: ${devices[$i]}\n" 1>&2
i=$(($i+1))
done
device=''
while [[ $device == '' ]]; do
printf 'select: ' 1>&2
read
device=${devices[$REPLY]}
done
printf "$adbpath -s $device"
}
adbrun() {
if [[ $* == '' || $* == '--help' || $* == 'devices' ]]; then
$adbpath $*
return
fi
$(adbs) $*
}
lss() { # last screen shot
count=$([ $1 ] && printf $1 || printf 1)
adbs=$(adbs)
while read -r file
do
$adbs pull "$file" ~/Pictures/Screenshots/
done < <($adbs shell ls -1td /sdcard/Pictures/Screenshots/* | head -n $count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment