header is a Bash utility that automatically adds or updates a standardized metadata header at the top of files (YAML, Bash, Python, configs, etc.).
It’s designed to help teams maintain consistent file documentation and versioning, while preserving shebangs (#!/usr/bin/env bash) and file permissions.
-
Adds a new header to files without one, or updates existing headers
-
Preserves shebang (
#!) line if present -
Preserves original file permissions
-
Header fields managed automatically:
- File – filename
- Author – preserved if exists; otherwise set to provided or current user
- Created On – preserved once set; otherwise added at creation
- Last Modified – always updated
- Modified By – always updated
- Description – preserved unless explicitly updated
- Version – starts at
v1.0, increments by0.1on each modification
Save the script and make it executable:
sudo cp header /usr/local/bin/header
sudo chmod 755 /usr/local/bin/headerTo automatically insert or update headers when editing YAML files, add the following to your ~/.vimrc (or globally in /etc/vim/vimrc):
autocmd BufRead,BufNewFile *.yml,*.yaml !header % # Not Recommended as this will give a warning message each time to Load the File
autocmd FileType yaml setlocal et ai ts=2 sw=2 sts=2 # RECOMMENDED FOR 2-SPACED-TABSheader [OPTIONS] FILE [FILE2 ...]| Option | Description |
|---|---|
-a, --author NAME |
Set author (default: current user) |
-m, --modified-by NAME |
Set Modified By field (default: current user) |
-d, --desc TEXT |
Set Description. Use "-" to preserve existing |
-f, --force-author |
Overwrite existing Author with the provided name |
-h, --help |
Show usage |
header --author "Alice" --desc "Production Configuration Template" sample.yamlheader -m "Bob" -d "Alice's code, modified by Bob" sample_with_header.yamlheader --author "Bob" --force-author app.yamlheader --author devops --desc "Infra configs" config1.yaml config2.yaml- Preserves Author and Created On by default
--force-authoris required to overwrite Author--desc "-"preserves existing description- Version auto-increments (
v1.0,v1.1,v1.2, …)