2020-07-25 23:39:09 +00:00
#!/usr/bin/env bash
2019-04-27 17:48:51 +00:00
if which tput >/dev/null 2>&1; then
2020-07-26 17:58:29 +00:00
ncolors=$(tput colors)
2019-04-27 17:48:51 +00:00
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
2020-07-26 17:58:29 +00:00
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
2019-04-27 17:48:51 +00:00
else
2020-07-26 17:58:29 +00:00
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
2019-04-27 17:48:51 +00:00
fi
error() {
2020-07-26 17:58:29 +00:00
printf "${BOLD}${RED}$1${NORMAL}"
2019-04-27 17:48:51 +00:00
}
abort() {
2020-07-26 17:58:29 +00:00
error "\nAborting...\n"
exit 1
2019-04-27 17:48:51 +00:00
}
set -e
cwd=$PWD
printf "${BOLD}Attempting to connect to device via adb...\nMake sure 'file transfer' mode is set on device. You may have to accept the connection and then re-run this script.\n${NORMAL}"
adb forward tcp:9222 localabstract:chrome_devtools_remote
src=_tabs.json
if wget -qO $src http://localhost:9222/json/list; then
2020-07-26 17:58:29 +00:00
ts=`date +"%Y-%m-%d_%H-%M-%S"`
dest="${cwd}/${ts}_android-chrome-tabs.md"
sed -n "/\"url\"/p" $src | sed -e "s/^[ \t]*.\{8\}//" -e "s/.\{2\}$//" > $dest
printf "${BOLD}Saved tabs to: ${YELLOW}$dest${NORMAL}\n"
2019-04-27 17:48:51 +00:00
else
2020-07-26 17:58:29 +00:00
error "Unable to download tabs from device!\n"
2019-04-27 17:48:51 +00:00
fi
rm $src