Xcode编译时自动创建一个webServer进行调试

  1. Mac如何吊起终端呢? 可以使用Applescript
#打开终端并起一个webServer
shellPath=`pwd`
#打开'iTerm'
osascript <<EOF
tell application "iTerm"
    tell current window
        create tab with default profile
        tell current session
            write text "cd ${shellPath}"
            write text "clear;"
            write text "sh server.sh"
        end tell
    end tell
end tell
EOF

#打开'Terminal'
#osascript <<EOF
#tell application "Terminal"
#    activate
#    set currentTab to do script "cd ${shellPath};clear;sh server.sh;"
#end tell
#EOF

server.sh

#! /bin/bash
#调用: webServer -p 8888

IP=$(ifconfig | sed -e '/.*inet /!d;s///;s/ .*//' | tail -n 1)
IP_PORT=8888
while getopts "p:" opt; do
  case $opt in
    p)
       IP_PORT=$OPTARG 
      ;;
    \?)
      IP_PORT=8888
      ;;
  esac
done

#先关闭指定的端口 避免占用导致开不成功~
kill -9 `lsof -t -i:$IP_PORT`

CurrentDir=`pwd`
echo "🚀 当前目录为:${CurrentDir},WebServer已开启"
IP=$(ifconfig | sed -e '/.*inet /!d;s///;s/ .*//' | grep "192.168")

#局域网ip 应该是192.168.xx.xx 
if [ "x${IP}" = "x" ] ;
then
    IP=$(ifconfig | sed -e '/.*inet /!d;s///;s/ .*//' | tail -n 1)
fi

echo "🏡 访问地址如下: "
serverURL="http://"$IP":${IP_PORT}"
echo "${serverURL}"
echo "🔥 欢迎使用~ 🔥"

posted @ 2023-12-15 21:09  CoderWGB  阅读(8)  评论(0编辑  收藏  举报