Skip to content

Instantly share code, notes, and snippets.

@simbafs
Last active June 14, 2021 07:11
Show Gist options
  • Save simbafs/9132289f63368ad325d6a2ef62be7a20 to your computer and use it in GitHub Desktop.
Save simbafs/9132289f63368ad325d6a2ef62be7a20 to your computer and use it in GitHub Desktop.
scrcpy.sh
#!/bin/bash
# credit: simba-fs
#
# color
BLUE='\033[1;34m'
NC='\033[0m' # No Color
wireless=0
ip=192.168.43.1
options=''
while getopts "f?w?h?help?i:" argv;
do
case $argv in
w)
wireless=1
;;
f)
options+='-f '
;;
i)
wireless=1
ip=$OPTARG
;;
h|help)
cat <<- EOF
Usage:
scrcpy.sh [-wfh] [-i <ip>]
Options:
-w enable wireless, default ip is '192.168.43.1'
-f enable fullscreen
-i enable wireless and use specified ip (you don\'t need to use -w
if -i is given)
-h print this message
Author:
simba-fs
https://github.com/simba-fs
EOF
exit
;;
*)
options+="$arg $OPTARG"
esac
done
echo $options
if [[ $wireless == 1 ]];then
echo -en $BLUE\> please plug your phone, enable USB debug in setting. And then press [enter]$NC
read
adb tcpip 5555
echo -en $BLUE\> unplug your phone and press [enter]$NC
read
adb connect $ip:5555
scrcpy $options
echo wireless
else
echo -en $BLUE\> please plug your phone, enable USB debug in setting. And then press [enter]$NC
read
scrcpy $options
fi
# reference
# getopts https://ithelp.ithome.com.tw/articles/10105866
# color https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
# scrcpy https://github.com/Genymobile/scrcpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment