Sign inSign up

gartisk/watch-and-prefix

By gartisk

•Updated 7 months ago

https://github.com/gartisk/watch-and-prefix

Image
Developer tools
0

222

gartisk/watch-and-prefix repository overview

⁠watch-and-prefix

Watches a .env file and writes a VAR-prefixed copy on every save.

Whenever you save the watched file, watch-and-prefix reads each variable line and prepends your chosen prefix — then writes the result to the destination you configured.
Blank lines, comments, and lines that already carry the prefix are left untouched (idempotent).


⁠Flags

FlagRequiredDescription
--file <FILE>✅Path to the file to watch
--var-prefix <PREFIX>✅Prefix prepended to every variable line (e.g. HOMEPAGE_VAR_)
--output <PATH>✅ (unless --overwrite)Destination — see the three forms below
--overwriteoptionalModify the source file in place. Mutually exclusive with --output
⁠--output path forms
FormExampleResult
Directory (trailing /)--output /out/Saves inside /out/ keeping the original filename
Full path--output /out/prefixed.envSaves as that exact file
Bare filename--output prefixed.envSaves next to the source file

⁠Ways to run

⁠1 — Directly (bash + inotify-tools)

Requires bash and inotify-tools (sudo apt install inotify-tools on Debian/Ubuntu).

# Save with a custom name into a specific folder
./watch-and-prefix.sh \
  --file config.env \
  --var-prefix HOMEPAGE_VAR_ \
  --output /tmp/output/homepage_config.env

# Save into a folder, keep the original filename
./watch-and-prefix.sh \
  --file config.env \
  --var-prefix HOMEPAGE_VAR_ \
  --output /tmp/output/

# Bare filename — saved next to the source file
./watch-and-prefix.sh \
  --file config.env \
  --var-prefix HOMEPAGE_VAR_ \
  --output prefixed.env

# Overwrite the source file in place (no separate output file)
./watch-and-prefix.sh \
  --file config.env \
  --var-prefix HOMEPAGE_VAR_ \
  --overwrite

⁠2 — Docker · local build (compose.local.yaml)

Builds the image straight from the local Dockerfile — no Docker Hub account needed.

# Build and run (foreground)
docker compose -f compose.local.yaml up --build

# Build and run (detached / background)
docker compose -f compose.local.yaml up --build -d

# Follow logs after detaching
docker compose -f compose.local.yaml logs -f

# Stop
docker compose -f compose.local.yaml down

Edit the command: block inside compose.local.yaml to change the file, prefix, or output path.


⁠3 — Docker · Docker Hub image (compose.yaml)

Uses a pre-built image from Docker Hub. Create a .env file at the project root:

DOCKER_USERNAME=gartisk
IMAGE_NAME=watch-and-prefix
IMAGE_TAG=latest

Then:

# Pull and run
docker compose up

# Detached
docker compose up -d

# Stop
docker compose down

⁠4 — Docker · one-liner (docker run)

No compose file needed — useful for quick tests or CI.

# Save with a custom name
docker run --rm \
  -v ./input:/watch/input:ro \
  -v ./output:/watch/output \
  your_dockerhub_username/watch-and-prefix:latest \
  watch-and-prefix.sh \
    --file /watch/input/config.env \
    --var-prefix HOMEPAGE_VAR_ \
    --output /watch/output/homepage_config.env

# Overwrite in place (only one volume mount needed)
docker run --rm \
  -v ./input:/watch/input \
  your_dockerhub_username/watch-and-prefix:latest \
  watch-and-prefix.sh \
    --file /watch/input/config.env \
    --var-prefix HOMEPAGE_VAR_ \
    --overwrite

Tag summary

Content type

Image

Digest

sha256:164f87a4a…

Size

4 MB

Last updated

7 months ago

docker pull gartisk/watch-and-prefix