Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Conversation

@Mild-Solvent
Copy link

@Mild-Solvent Mild-Solvent commented Feb 10, 2025

No, .bat files are specific to Windows and cannot be executed on Linux or macOS. For Linux and macOS, you need to use a shell script (.sh file). Below, I'll provide a cross-platform solution that includes:

  1. A .bat script for Windows.
  2. A .sh script for Linux and macOS.

Windows Script (run.bat)

@echo on
REM Ensure the script is running in the correct directory (where package.json is located)
echo Running in directory: %cd%

REM Install dependencies
echo Installing dependencies...
npm install

REM Check if the dist folder exists and contains the required files
if exist "dist\cursor-reset-linux" if exist "dist\cursor-reset-macos" if exist "dist\cursor-reset-win.exe" (
    echo Required files found in the dist folder.
) else (
    echo Required files not found. Building the project...
    npm run build:all
)

REM Ask the user to choose which file to run based on their operating system
echo Please select your operating system:
echo 1. Linux
echo 2. macOS
echo 3. Windows
set /p choice="Enter the number corresponding to your OS: "

REM Run the appropriate file based on the user's choice
if "%choice%"=="1" (
    echo Running cursor-reset-linux...
    dist\cursor-reset-linux
) else if "%choice%"=="2" (
    echo Running cursor-reset-macos...
    dist\cursor-reset-macos
) else if "%choice%"=="3" (
    echo Running cursor-reset-win.exe...
    dist\cursor-reset-win.exe
) else (
    echo Invalid choice. Exiting...
    pause
    exit /b
)

REM Optional: Keep the window open after the command runs
pause

Linux/macOS Script (run.sh)

#!/bin/bash
# Ensure the script is running in the correct directory (where package.json is located)
echo "Running in directory: $(pwd)"

# Install dependencies
echo "Installing dependencies..."
npm install

# Check if the dist folder exists and contains the required files
if [[ -f "dist/cursor-reset-linux" && -f "dist/cursor-reset-macos" && -f "dist/cursor-reset-win.exe" ]]; then
    echo "Required files found in the dist folder."
else
    echo "Required files not found. Building the project..."
    npm run build:all
fi

# Ask the user to choose which file to run based on their operating system
echo "Please select your operating system:"
echo "1. Linux"
echo "2. macOS"
echo "3. Windows"
read -p "Enter the number corresponding to your OS: " choice

# Run the appropriate file based on the user's choice
if [[ "$choice" == "1" ]]; then
    echo "Running cursor-reset-linux..."
    ./dist/cursor-reset-linux
elif [[ "$choice" == "2" ]]; then
    echo "Running cursor-reset-macos..."
    ./dist/cursor-reset-macos
elif [[ "$choice" == "3" ]]; then
    echo "Running cursor-reset-win.exe..."
    echo "This script is running on Linux/macOS. Windows executables cannot be run here."
else
    echo "Invalid choice. Exiting..."
    exit 1
fi

How to Use:

For Windows:

  1. Double-click the run.bat file to execute it.

For Linux/macOS:

  1. Open a terminal in the project folder.
  2. Make the script executable:
    chmod +x run.sh
  3. Run the script:
    ./run.sh

Key Differences Between Scripts:

Feature Windows (.bat) Linux/macOS (.sh)
File Extension .bat .sh
Directory Check %cd% $(pwd)
File Existence Check if exist "path\to\file" if [[ -f "path/to/file" ]]; then
User Input set /p choice="Enter choice: " read -p "Enter choice: " choice
Executable Run Command dist\cursor-reset-win.exe ./dist/cursor-reset-linux
Line Endings CRLF (Windows) LF (Unix)

Cross-Platform Notes:

  1. File Permissions:

    • On Linux/macOS, ensure the cursor-reset-linux and cursor-reset-macos files are executable. You can make them executable using:
      chmod +x dist/cursor-reset-linux
      chmod +x dist/cursor-reset-macos
  2. Windows Executable on Linux/macOS:

    • The script will notify the user if they try to run cursor-reset-win.exe on Linux/macOS, as it is not compatible.
  3. Build Command:

    • The npm run build:all command is assumed to generate the required files (cursor-reset-linux, cursor-reset-macos, and cursor-reset-win.exe) in the dist folder.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant