MacOS Custom Script

A collection of scripts to make your life easier on MacOS as a developer.

View on GitHub

πŸ› οΈ Collect .env Files Script for macOS

This script searches your entire macOS filesystem for .env* files (e.g., .env, .env.local, .env.production, etc.), then copies them to your Desktop in a folder named envs, renaming each file to reflect its full path using dot notation.

You can run this from anywhere using the command: collect-envs


πŸ“Œ Features


πŸš€ Setup Instructions

1. Create the Script File

mkdir -p ~/bin
nano ~/bin/collect-envs

2. Paste the Following Script

#!/bin/bash

# Define the target directory
TARGET_DIR="$HOME/Desktop/envs"

# Create the target directory if it doesn't exist
mkdir -p "$TARGET_DIR"

echo "πŸ” Scanning filesystem for .env* files. This may take a while..."

# Find and process .env* files
sudo find / -type f -name ".env*" 2>/dev/null | while read file; do
  # Remove leading slash
  relative_path="${file#/}"

  # Get folder path and env file name
  folder_path="$(dirname "$relative_path")"
  env_name="$(basename "$file")"

  # Replace slashes with dots and remove leading dot from filename
  new_name="${folder_path//\//.}.${env_name#.}"

  # Full destination path
  dest="$TARGET_DIR/$new_name"

  # Copy the file (overwrite if exists)
  cp -f "$file" "$dest"
done

echo "βœ… All .env* files copied to: $TARGET_DIR"

3. Make the Script Executable

chmod +x ~/bin/collect-envs

4. Add ~/bin to Your PATH (If Needed)

If it’s not already in your PATH, add it to your shell config file:

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

(Use .bashrc instead if you use Bash.)


πŸ§ͺ Usage

Once installed, simply run:

collect-envs

πŸ›‘ You may be prompted for your password due to sudo access required for full system scanning.


πŸ“‚ Example Output

If the original file is:

/Users/arif/Projects/my-app/.env.local

It will be copied and renamed as:

~/Desktop/envs/Users.arif.Projects.my-app.env.local

🧹 Optional Improvements


βœ… License

Feel free to copy, modify, and share!


πŸ“§ Contact

If you find this script useful or have suggestions for improvements, feel free to reach out!