一行命令冷啟動後,即可開始編寫程式碼[標題黨]

小李世界發表於2022-12-13

前言

一個小工具

完全新手,程式碼寫的不好,請見諒。

使用

另存到 bin 目錄,名字自取,如 lrs(Laravel + React, Start!)

lrs 啟動

lrs stop 停止

程式碼

#!/bin/bash

# 環境:macOS
# 功能:快速啟動 PhpStorm 和 WebStorm 以進行 Laravel 和 React 前後分離專案的程式碼開發

# Laravel
Laravel="Laravel"
LaravelPath="antic-api" # 資料夾名

# React
React="React"
ReactPath="antic"
PackageManager="yarn"

if [ "$1" = "stop" ]; then
    ps -fe | grep "php $LaravelPath/artisan serve" | grep -v grep > /dev/null
    if [ $? -ne 1 ]
    then
        echo "stopping $Laravel"
        ps -fe | grep "php $LaravelPath/artisan serve" | grep -v grep | awk '{print $2}' | xargs kill -9;
        echo 'kill process result :'$?;
    fi

    ps -fe | grep "soketi-server" | grep -v grep > /dev/null
    if [ $? -ne 1 ]
    then
        echo "stopping soketi"
        ps -fe | grep "soketi-server" | grep -v grep | awk '{print $2}' | xargs kill -9;
        echo 'kill process result :'$?;
    fi

    ps -fe | grep "cwd $ReactPath start" | grep -v grep > /dev/null
    if [ $? -ne 1 ]
    then
        echo "stopping $React"
        ps -fe | grep "cwd $ReactPath start" | grep -v grep| awk '{print $2}' | xargs kill -9;
        echo 'kill process result :'$?;
    fi

    exit;
fi

cd ~/PhpstormProjects/ # PhpStorm 預設資料夾
phpstorm $LaravelPath
cd ~/WebstormProjects/ # WebStorm 預設資料夾
webstorm $ReactPath

# Laravel
cd ~/PhpstormProjects/
ps -fe | grep "php $LaravelPath/artisan serve"|grep -v grep >/dev/null
if [ $? -ne 0 ]
then
    echo "starting $Laravel"
    screen -dmS $Laravel php $LaravelPath/artisan serve
else
    echo "${Laravel} running"
fi

# sokeit
ps -fe | grep "soketi-server" | grep -v grep > /dev/null
if [ $? -ne 0 ]
then
    echo "starting soketi"
    cd $LaravelPath
    screen -dmS soketi soketi start
else
    echo "soketi running"
fi

# React
cd ~/WebstormProjects/
ps -fe | grep "cwd $ReactPath start" | grep -v grep > /dev/null
if [ $? -ne 0 ]
then
    echo "starting $React"
    screen -dmS $React $PackageManager  --cwd $ReactPath start
else
    echo "$React running"
fi
本作品採用《CC 協議》,轉載必須註明作者和本文連結
無論在現實或是網路中,我都是孤獨的。

相關文章