Add script to get Chrome tabs from an Android device
This commit is contained in:
parent
c8aa6c3c51
commit
3f37380e67
50
bin/sync-android-chrome-tabs.sh
Normal file
50
bin/sync-android-chrome-tabs.sh
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if which tput >/dev/null 2>&1; then
|
||||||
|
ncolors=$(tput colors)
|
||||||
|
fi
|
||||||
|
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
|
||||||
|
RED="$(tput setaf 1)"
|
||||||
|
GREEN="$(tput setaf 2)"
|
||||||
|
YELLOW="$(tput setaf 3)"
|
||||||
|
BLUE="$(tput setaf 4)"
|
||||||
|
BOLD="$(tput bold)"
|
||||||
|
NORMAL="$(tput sgr0)"
|
||||||
|
else
|
||||||
|
RED=""
|
||||||
|
GREEN=""
|
||||||
|
YELLOW=""
|
||||||
|
BLUE=""
|
||||||
|
BOLD=""
|
||||||
|
NORMAL=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
error() {
|
||||||
|
printf "${BOLD}${RED}$1${NORMAL}"
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
error "\nAborting...\n"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
error "Unable to download tabs from device!\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm $src
|
||||||
|
|
|
@ -60,15 +60,12 @@ is_valid_sym_path() {
|
||||||
|
|
||||||
windows_path() {
|
windows_path() {
|
||||||
ret=$1
|
ret=$1
|
||||||
|
|
||||||
if [[ $(is_drive_path $ret) -eq 1 ]]; then
|
if [[ $(is_drive_path $ret) -eq 1 ]]; then
|
||||||
ret="${ret/\//}"
|
ret="${ret/\//}"
|
||||||
# Fix the drive name, e.g. c\foo becomes c:\foo
|
# Fix the drive name, e.g. c\foo becomes c:\foo
|
||||||
ret=$(sed 's,\([a-zA-Z]*\),\1:,' <<< "$ret")
|
ret=$(sed 's,\([a-zA-Z]*\),\1:,' <<< "$ret")
|
||||||
fi
|
fi
|
||||||
|
ret="${ret////\\}" # Replace Unix path with Windows path.
|
||||||
ret="${ret////\\}" # replace unix path with windows path
|
|
||||||
|
|
||||||
echo $ret
|
echo $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,29 +74,29 @@ set -e
|
||||||
cwd=$PWD
|
cwd=$PWD
|
||||||
platform=`uname` # 'Linux', 'Darwin', etc
|
platform=`uname` # 'Linux', 'Darwin', etc
|
||||||
|
|
||||||
printf "${BOLD}What's the link file's path and name?\n${YELLOW}> ${NORMAL}"
|
printf "${BOLD}${YELLOW}Enter full path to source file/dir:\n${NORMAL}"
|
||||||
read -e link_name
|
read -e source_path
|
||||||
if [[ $(is_valid_sym_path $link_name) -eq 0 ]]; then
|
if [[ $(is_valid_sym_path $source_path) -eq 0 ]]; then
|
||||||
error "This path is invalid. Only symbolic and absolute paths and allowed."
|
|
||||||
abort
|
|
||||||
fi
|
|
||||||
|
|
||||||
test -d "$link_name" && error "That is an existing folder!" && abort
|
|
||||||
test -e "$link_name" && error "That file already exists!" && abort
|
|
||||||
link_name=$(windows_path $link_name)
|
|
||||||
|
|
||||||
printf "${BOLD}Where should it point to?\n${YELLOW}> ${NORMAL}"
|
|
||||||
read -e link_path
|
|
||||||
if [[ $(is_valid_sym_path $link_path) -eq 0 ]]; then
|
|
||||||
error "This path is invalid. Only symbolic and absolute paths are allowed."
|
error "This path is invalid. Only symbolic and absolute paths are allowed."
|
||||||
abort
|
abort
|
||||||
fi
|
fi
|
||||||
! test -d "$link_path" && ! test -e "$link_path" && error "That path doesn't exist!" && abort
|
! test -d "$source_path" && ! test -e "$source_path" && error "That path doesn't exist!" && abort
|
||||||
link_path=$(windows_path $link_path)
|
source_path=$(windows_path $source_path)
|
||||||
|
|
||||||
cmd="cmd //c 'mklink $link_name $link_path'"
|
|
||||||
|
|
||||||
printf "\n${BOLD}${BLUE}About to link ${GREEN}$link_name${BLUE} to ${GREEN}$link_path${NORMAL}\n"
|
printf "${BOLD}${YELLOW}Enter full path to symlink destination:\n${NORMAL}"
|
||||||
|
read -e link_dest
|
||||||
|
if [[ $(is_valid_sym_path $link_dest) -eq 0 ]]; then
|
||||||
|
error "This path is invalid. Only symbolic and absolute paths and allowed."
|
||||||
|
abort
|
||||||
|
fi
|
||||||
|
test -d "$link_dest" && error "That is an existing folder!" && abort
|
||||||
|
test -e "$link_dest" && error "That file already exists!" && abort
|
||||||
|
link_dest=$(windows_path $link_dest)
|
||||||
|
|
||||||
|
cmd="cmd //c 'mklink $link_dest $source_path'"
|
||||||
|
|
||||||
|
echo "${BOLD}${BLUE}About to create link ${GREEN}$link_dest${BLUE} to source ${GREEN}$source_path${NORMAL}"
|
||||||
printf "\n${BOLD}Enter 1 to proceed\n${YELLOW}> ${NORMAL}"
|
printf "\n${BOLD}Enter 1 to proceed\n${YELLOW}> ${NORMAL}"
|
||||||
read confirm
|
read confirm
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user