当前位置: 首页 > 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.lryc.cn/news/614660.html

相关文章:

  • 免费PDF批量加密工具
  • 从零掌握 Java AWT:原理、实战与性能优化
  • 【沉浸式解决问题】pycharm关闭科学模式
  • 杰理ac791 [Info]: [LL_S]Recv - LL_CHANNEL_MAP_REQ
  • Python从入门到精通计划Day07: Python数据卷轴术:文件魔法与防御结界全指南
  • nlp-语义分析
  • 在 Vue 中使用 ReconnectingWebSocket实现即时通讯聊天客服功能
  • Java 使用 SSHJ 执行 SSH 命令和 SFTP 文件上传和下载
  • 【前端后端部署】将前后端项目部署到云服务器
  • Redis(④-消息队列削峰)
  • 吴恩达 深度学习笔记
  • Coze Studio 概览(九)--插件管理
  • 配电线路故障定位在线监测装置的技术解析与应用价值
  • 应急响应流程
  • 基于 C++ 的湍流数值模拟理论报告
  • 从零构建桌面写作软件的书籍管理系统:Electron + Vue 3 实战指南
  • 中小业务遭遇网络攻击,防护能力不足的解决办法​
  • electron 静默安装同时安装完成后自动启动(nsis)
  • Spark在什么情况下CBO才会判断失误,如何避免
  • 服务器登上去,显示 failed to send WATCHDOG 重启有效吗?
  • Uber的MySQL实践(一)——学习笔记
  • I/O原理与服务。
  • 智慧交通场景下 mAP↑28%:陌讯多模态融合算法实战解析
  • OpenAI 开源模型 GPT-OSS MCP服务器深度解密:从工具集成到系统提示全自动化,浏览器+Python无缝协同的底层逻辑
  • 微软Azure AI Foundry正式上线GPT-5系列模型
  • CORS 跨域问题 Next.js 跨域问题放通
  • 《从零构建大语言模型》学习笔记2,文本数据处理1(以及tiktoken库无法下载gpt2参数,调用get_encoding时SSL超时的解决方法)
  • 中国的超算中心使用情况如何?是否算力过剩
  • Eyevinn 彻底改变开源部署模式
  • 初步认识AMSU-A/B、HIRS-3/4、MHS、ATMS、GOES