当前位置: 首页 > news >正文

Mac 电脑放在环境变量中的通用脚本

mac电脑下放在环境变量中,方便提高效率执行
注:相关路径需要根据实际情况进行更新
需要在 .bash_profile 文件中定义如下(路径需要做实际替换):

source $HOME/software/scripts/base_profile.sh
source $HOME/software/scripts/custom_profile.sh

custom_profile.sh 通用内容如下:

# 将时间戳格式化为可读形式,示例: ts2 1714471312123 结果:2024-04-30 18:01:52.123
ts2() {local timestamp=$1# 检查输入是否纯数字if ! [[ "$timestamp" =~ ^[0-9]+$ ]]; thenecho "错误:时间戳必须是数字!" >&2return 1fi# 检查位数(10位=秒级,13位=毫秒级)local length=${#timestamp}if (( length == 10 )); then# 秒级时间戳date -r "$timestamp" "+%Y-%m-%d %H:%M:%S"elif (( length == 13 )); then# 毫秒级时间戳local milliseconds=$((timestamp % 1000))local seconds=$((timestamp / 1000))date -r "$seconds" "+%Y-%m-%d %H:%M:%S.${milliseconds}"elseecho "错误:时间戳必须是 10 位(秒级)或 13 位(毫秒级)!" >&2return 1fi
}# 使用示例: error demo
error(){# 红底白字echo -e "\033[41;37m $1 \033[0m"
}# 使用示例: info demo
info(){# 绿字echo -e "\033[47;32m $1 \033[0m"
}# 需要修改相关路径
# buildandroidcmd(){
#   echo "注意需要在 build 目录执行,且确保相关代码能正常执行"
#   echo "构建 Android 平台可执行程序"
#   cmake .. -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-21
#   cmake --build .
# }# adb cmd
alias a='adb shell'
alias akill='adb kill-server'
alias astart='adb start-server'
alias apush='adb push '
alias apull='adb pull '
alias areboot='adb reboot'
alias atop='adb shell dumpsys activity top'
alias astop='adb shell top'
alias arecovery='adb reboot recovery'
alias abootloader='adb reboot bootloader'
alias alog='adb logcat'
alias alogcrash='adb logcat -b crash'
alias aloge='adb logcat -v time *:E'
alias lsime='adb shell ime list -s'
alias lspkg='adb shell pm list packages'
alias img='imgcat'alias lf='exa -l --time-style=full-iso'
alias lt='exa -T -l'
alias ll='exa -l'
alias grepnr='grep -n -r'# other cmd
alias rmdir='rm -r'alias obash='o ~/.bash_profile'
alias sbash="source ~/.bash_profile"# git 相关操作
alias giturl="git remote get-url origin"
alias gurl="git remote get-url origin"
alias gbr="git br -a |grep \"\""
alias gpull="git pull"
alias gclone="git clone "
alias gst="git status "
alias gco="git co "
alias gcheck="git checkout "alias kill9='kill -9 'alias ahome='adb shell input keyevent 3'
alias aback='adb shell input keyevent 4'# 修改后生效
# alias ocus='o $HOME/software/scripts/custom_profile.sh'
# 预期需要修改 author 后的内容
alias glastweek="git log --pretty=format:\"%an: %s\" --since=1.weeks --author=yongchao.yyc|grep yongchao"setproxy(){echo "first we clear the config of proxy before"adb shell settings put global http_proxy :0 echo "now we wait for it to finish for 2 second "sleep 2echo "second we set the proxy"info "ip:${1}  port:${2}"adb shell settings put global http_proxy $1:$2
}gitcheck(){git checkout -b $* origin/$*
}# 需要按实际情况修改后生效
# code(){
#   Open -a /Applications/Code.app $1
# }apkg(){adb shell dumpsys window |grep mCurrentFocus
}# 需要修改完路径后使用
# pstack(){
#    ndk-stack -sym $1 -dump /Users/muyi/Desktop/engine/crash/$2
# }tailf(){tail -f $*
}gclonetag(){git clone $1 --branch $2 --single-branch
}ft(){grep -rnw . -e $*
}# 将指定 so 替换指定包名中的指定动态库(设备需要root), 使用示例:pushsoto libxxx.so com.demo.app
pushsoto(){if adb shell "command -v su" >/dev/null 2>&1; thenecho "Device is rooted"elseerror "Device is not rooted, cant run this commond"returnfiso_file_path=$1so_dir=$(dirname "$so_file_path")echo "so_dir is:"echo "\t$so_dir"so_name=$(basename "$so_file_path")echo "so_name is:"echo "\t$so_name"(cd $so_dirresult=$(adb shell pm path $2)if [ $? -eq 0 ]thenfull_path=${result#package:}dir_path=$(dirname "$full_path")echo "app path:"echo "\t$dir_path"echo "push so to sdcard"push_result=$(adb push $so_name /sdcard/)echo "\t$push_result"echo "move so to"echo "\t$dir_path/lib/arm64"adb shell "su -c 'mv /sdcard/$so_name $dir_path/lib/arm64'"echo "run chmod command"adb shell "su -c 'chmod 777 $dir_path/lib/arm64/$so_name'"elseerror "Failed to execute adb command, please make sure you device is ok"fi)
}pushsoto32() {if adb shell "command -v su" >/dev/null 2>&1; thenecho "Device is rooted"elseerror "Device is not rooted, cant run this commond"returnfiso_file_path=$1so_dir=$(dirname "$so_file_path")echo "so_dir is:"echo "\t$so_dir"so_name=$(basename "$so_file_path")echo "so_name is:"echo "\t$so_name"(cd $so_dirresult=$(adb shell pm path $2)if [ $? -eq 0 ]thenfull_path=${result#package:}dir_path=$(dirname "$full_path")echo "app path:"echo "\t$dir_path"echo "push so to sdcard"push_result=$(adb push $so_name /sdcard/)echo "\t$push_result"echo "move so to"echo "\t$dir_path/lib/arm"adb shell "su -c 'mv /sdcard/$so_name $dir_path/lib/arm'"echo "run chmod command"adb shell "su -c 'chmod 777 $dir_path/lib/arm/$so_name'"elseerror "Failed to execute adb command, please make sure you device is ok"fi)
}# sign(){
#   jarsigner -verbose -keystore /Users/muyi/software/key_store/sign.keystore -signedjar sign_$1 $1 lonewolf -digestalg SHA1 -sigalg MD5withRSA
# }# dex2jar(){
#   sh /Users/muyi/software/tools/android_killer/dex2jar/d2j-dex2jar.sh $*
# }# de(){
#   java -jar /Users/muyi/software/tools/android_killer/bin/apktool/apktool/ShakaApktool.jar  d $*
# }# en(){
#   java -jar /Users/muyi/software/tools/android_killer/bin/apktool/apktool/ShakaApktool.jar  b $*
# }# decode(){
#   java -jar /Users/muyi/software/tools/android_killer/apktool_240.jar d $*
# }# apktool(){
#  java -jar /Users/muyi/software/tools/android_killer/apktool_270.jar $* 
# }# jd(){
#   java -jar /Users/muyi/software/tools/android_killer/jdgui141.jar
# }setime(){adb shell ime set $*
}apkpath(){adb shell pm path $*
}port(){lsof -i:$*
}lsport(){lsof -i:$*
}tap(){adb shell input tap $*
}swipe(){adb shell input swipe $*
}send(){adb shell am broadcast -a  $* 
}ascheme(){adb shell am start $*
}clearapp(){adb shell pm clear $*
}kapp(){adb shell am force-stop $*
}input(){adb shell am broadcast -a ADB_INPUT_TEXT --es msg $*
}f(){grep -R $* .
}aconip(){adb tcpip 5555sleep 3adb connect $*:5555adb devices -l
}cbuild(){cmake .make
}acon(){adb tcpip 5555sleep 3line="------------------------------------------\r\n"echo "now we fetch the ip of android device"aip=`aip`echo "ip is ${aip}"echo ${line}echo "now we connect"echo "${aip}:5555"adb connect "${aip}:5555"echo ${line}adb devices -l
}adis(){adb disconnect
}awifi(){adb tcpip 5555ip=`aip`echo "device's ip is ${ip}"adb connect ${ip}
}# 获取 ip 地址
ip(){ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
}# 获取 ip 地址并拷贝到粘贴板(针对 mac os)
ipcp(){ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"| pbcopy
}aip(){adb shell ifconfig |grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
}# sh 的封装,在脚本执行结束后弹窗提示
ish(){sh $*say script finishosascript -e 'display notification "脚本执行完成" with title "ish"'
}kclient(){lsof -i tcp:12345 |grep ython | awk '{print $2}' |xargs kill -9
}# 获取对应文件的行数
count(){wc -l $*
}fsize(){du -sh $*
}# 安装 apk ,并在结束时给予声音和通知栏提示(针对 mac os)
apk(){result=$(echo $* | grep "Amap")if [[ "$result" != "" ]]theninfo "now we try to uninstall amap first"unainfo "then we intall"fiadb install $*# 以下两行针对 mac os# say "install finish"osascript -e 'display notification "安装完成" with title "apk"'# if [[ "$result" != "" ]]# then#       oa# else#       echo "不包含"# fi
}# 向鸿蒙手机安装包
hap(){hdc install $*osascript -e 'display notification "安装完成" with title "hap"'
}# 在控制台打印信息并在mac通知中显示对应信息
shownoti(){echo $*osascript -e 'display notification "'$*'" with title "脚本"'
}# 卸载指定包名的app
unapp(){adb uninstall $* 
}# 使用 SublimeText 打开内容
# 需要修改对应路径
# o(){
#   Open -a /Applications/SublimeText.app $1
# }# 查看 apk 包信息
apkdump(){aapt dump badging  $1
}# 查看已连接设备
list(){adb devices -l
}# 对Android设备执行录屏,ctrl+c结束录屏
arecord() {result=`adb devices -l |grep product |wc -l | tr -cd "[0-9]" `if [[ ${result} == "1" ]]; thenecho "连接了一台设备"else  error "已连接 ${result} 台设备,请确保有且仅有一台设备连接"returnfiif [ $# -eq 0 ]thenname="record"elsename="record$1"fi  trap 'onCtrlC' INTfunction onCtrlC () {running=falsetrap -- '' INT}info "开始录屏"adb shell screenrecord /sdcard/demo${name}.mp4info "录屏结束,等待录屏正常停止..."  sleep 5info "现在拉取视频..."target_dir="/Users/muyi/Pictures/videos"adb pull /sdcard/demo${name}.mp4 ${target_dir}/${name}.mp4info "视频已保存到:$target_dir"echo "文件名为:${name}.mp4"echo "完整路径为:${target_dir}/${name}.mp4"
}# 对当前设备截图保存到命令执行所在目录且将其打开
# 需要修改路径
asp() {target_dir="/Users/muyi/Pictures/screenshots"# current=`date "+%Y-%m-%d %H:%M:%S"`     #获取当前时间,例:2015-03-11 12:33:41       # timeStamp=`date -f "$current" +%s`      #将current转换为时间戳,精确到秒# currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #将current转换为时间戳,精确到毫秒if [ $# -eq 0 ]then# name=${currentTimeStamp}".png"name="screenshot.png"elsename="$1.png"if [ $# -eq 2 ]thentarget_dir=$2fifiadb shell screencap -p /sdcard/${name}adb pull /sdcard/${name} ${target_dir}/${name}adb shell rm /sdcard/${name}echo "save to $target_dir/${name}"# for mac osopen $target_dir"/"$name
}
http://www.dtcms.com/a/321144.html

相关文章:

  • 从浅拷贝到深拷贝:C++赋值运算符重载的核心技术
  • SITIME汽车时钟发生器Chorus保障智能汽车安全
  • 《告别Bug!GDB/CGDB调试实战指南》
  • 「iOS」————优先级反转
  • 解决Docker部署的MySQL8错误日志里面的 mbind: Operation not permitted 问题
  • 构建安全 Web 应用:从用户认证与授权到 JWT 原理解析
  • python使用python-docx自动化操作word
  • 【杂谈】-逆缩放悖论:为何更多思考会让AI变“笨“?
  • Numpy科学计算与数据分析:Numpy布尔索引与花式索引实战
  • 一种对白点进行多重加权并利用三角剖分插值微调白平衡增益的白平衡矫正算法
  • RAG问答系统:Spring Boot + ChromaDB 知识库检索实战
  • 3D Tiles 格式中,Bounding Volum
  • 基于AutoDL平台的3D_Gaussian_Splatting初体验
  • 在 Vue 中使用 ReconnectingWebSocket实现即时通讯聊天客服功能
  • 2025 前端真实试题-阿里面试题分析
  • 关于数据结构6-哈希表和5种排序算法
  • Maptalks vs Cesium
  • 【最新版】2025年搜狗拼音输入法
  • “电子合同”为什么会出现无效的情况?
  • OpenCV cv2.flip() 函数详解与示例
  • 深入理解 Java AWT Container:原理、实战与性能优化
  • ORACLE看当前连接数的方法
  • 柠檬笔试——野猪骑士
  • 南方略咨询与与清源科技正式启动国际市场GTM流程规划咨询项目!!!
  • 汽车电子:现代汽车的“神经中枢“
  • Eyevinn 彻底改变开源部署模式
  • 小孙学变频学习笔记(十三)电动机参数的自动测量 矢量控制的转速反馈
  • 如何 让ubuntu 在root 下安装的docker 在 普通用户下也能用
  • Spring Boot 结合 CORS 解决前端跨域问题
  • GitLab同步提交的用户设置