---
type: collection
section: snippets
generated_at: 2026-06-18T03:27:16+02:00
total_entries: 2
tag_filter: Script
---

# Snippets

## Find Dirty Git Repositories

---
type: snippet
id: yqeihixirgfk24gh
title: Find Dirty Git Repositories
url: >
  https://www.jakubpelak.com/snippets/find-dirty-git-repositories
section: snippets
tags:
  - Git
  - Automation
  - CLI
  - Script
published_at: 2025-08-08
---

A tiny shell script that recursively scans a directory for Git repositories with uncommitted changes, nicknamed `dirgit`—a play on words combining "directory", "dirty", and "git".

```bash
#!/bin/bash

# Use current directory or first argument
ROOT="${1:-$(pwd)}"

# Find all Git repositories and check for dirty state
find "$ROOT" -type d -name ".git" 2>/dev/null | while read -r gitdir; do
    repo="$(dirname "$gitdir")"
    cd "$repo" || continue
    if [[ -n $(git status --porcelain) ]]; then
        echo "$repo"
    fi
done
````

Save it as `dirgit` (or any name you prefer), make it executable (`chmod +x dirgit`), and place it in `/usr/local/bin` or `~/bin` to use it globally.

### Usage

```bash
dirgit         # scan current directory
dirgit ~/code  # scan a specific directory
```

## Rename PNG Files to Random UUIDs

---
type: snippet
id: kowznhljjrgeq9r2
title: Rename PNG Files to Random UUIDs
url: >
  https://www.jakubpelak.com/snippets/rename-png-files-to-random-uuids
section: snippets
tags:
  - Automation
  - CLI
  - UUID
  - Script
published_at: 2025-03-09
---

A simple Bash script that renames all `.png` files in the current directory using randomly generated lowercase UUIDs. It ensures `uuidgen` is installed before execution and skips renaming if no PNG files are found.

```bash
#!/bin/bash

# Check if 'uuidgen' command is available
if ! command -v uuidgen &> /dev/null; then
  echo "uuidgen command not found. Please install it first."
  exit 1
fi

# Loop through all .png files in the current directory
for file in *.png; do
  # Skip if no PNG files found
  if [ ! -e "$file" ]; then
    echo "No PNG files found in the current directory."
    exit 0
  fi

  # Generate a random UUID v4 and convert to lowercase
  uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')

  # Rename the file
  mv "$file" "${uuid}.png"
done

echo "All PNG files have been renamed to random lowercase UUIDs."
```

> [!NOTE]
> Prefer a right-click service on macOS? See the AppleScript variant: (link: page://2lpiw0jmwjyaammm text: Rename Files to Random UUIDs via macOS Shortcuts).

