Skip to main content

Tool to automatically add, update, or delete multi-format copyright headers

Project description

pre-commit.ci status publish to PyPI semantic-release


cr-manager -- the Copyright Header Manager

A tool to automatically add, update, or delete multi-format copyright headers in source files.


GitHub Release GitHub Downloads Python PyPI version Install with pipx Linux macOS Windows License



Features

  • Add: Insert copyright headers for multiple file types.
  • Update: Force update or insert headers if missing.
  • Check: Verify the presence and correctness of headers.
  • Delete: Remove detected copyright headers from files.
  • Supports recursive directory traversal and filetype auto-detection or override.
  • Supports combined author-info and copyright headers.

How to Contribute


Action Modes

without any action mode specified, the default action is to add copyright headers.

OPTION DESCRIPTION
Add mode: Automatically adds copyright headers to files (default).
--add Add mode: Automatically adds copyright headers to files (default).
--check Check mode: Verifies file copyright status (match, mismatch, or not found).
--delete Delete mode: Removes detected copyright headers from files.
--update Update mode: Forces replacement of copyright or adds it if missing.

Add New Copyright Headers

# single file
$ cr-manager /path/to/file
# or
$ cr-manager --add /path/to/file

# files recursively in directories
$ cr-manager --recursive /path/to/directory
# or
$ cr-manager --add --recursive /path/to/directory

# add to non-supported suffixes with supplied filetype
# -- e.g. add to .txt files as python files --
$ cr-manager --filetype python /path/to/file.txt
# or
$ cr-manager --add --filetype python /path/to/file.txt

Update Existing Copyright Headers

--filetype <TYPE> can be used to force a specific filetype for the update action, overriding auto-detection.

# single file
$ cr-manager --update /path/to/file

# files recursively in directories
$ cr-manager --update --recursive /path/to/directory

Delete Existing Copyright Headers

--filetype <TYPE> can be used to force a specific filetype for the delete action, overriding auto-detection.

# single file
$ cr-manager --delete /path/to/file

# files recursively in directories
$ cr-manger --delete --recursive /path/to/directory

Debug Mode

# *add* without modifying files
$ cr-manager --debug /path/to/file
# or
$ cr-manager --add --debug /path/to/file

# *update* without modifying files
$ cr-manager --update --debug /path/to/file

# *delete* without modifying files
$ cr-manager --delete --debug /path/to/file

Supported File Types and Formats

FILETYPE SUFFIXES
python, shell, bash, sh, dockerfile .py, .sh, .dockerfile
$ cr-manager --filetype python
# ============================================================================ #
# Copyright © 2026 marslo                                                      #
# Licensed under the MIT License, Version 2.0                                  #
# ============================================================================ #

Python


FILETYPE SUFFIXES
jenkinsfile, groovy, gradle, java .groovy, .java
$ cr-manager --filetype groovy
/**
 *******************************************************************************
 * Copyright © 2026 marslo                                                     *
 * Licensed under the MIT License, Version 2.0                                 *
 *******************************************************************************
**/

java-groovy


FILETYPE SUFFIXES
c, cpp, c++, cxx, h, hpp, hxx .c, .cpp, .cxx, .h, .hpp, .hxx
$ cr-manager --filetype cpp
/**
 * Copyright © 2026 marslo
 * Licensed under the MIT License, Version 2.0
 */

c/cpp


pre-commit hook

cr-manager pre-commit hook

# if `COPYRIGHT` file can be found in the root directory of this repository
---
repos:
  - repo: https://github.com/marslo/cr-manager
    rev: v4.0.0
    hooks:
      - id: cr-manager
        args: ["--update"]
# specify the path to the COPYRIGHT file
---
repos:
  - repo: https://github.com/marslo/cr-manager
    rev: v4.0.0
    hooks:
      - id: cr-manager
        args: ["--update", "--copyright", "/path/to/COPYRIGHT"]
        files: ^(jenkinsfile/|.*\.(groovy|py|sh)$)
# only check the copyright headers without modifying files after commit
---
repos:
  - repo: https://github.com/marslo/cr-manager
    rev: v4.0.0
    hooks:
      - id: cr-manager
        args: ["--check"]
        stages: [post-commit]

Install

Binary

  • pipx installation ( how to install pipx )
    $ python3 -m pip install pipx
    $ python3 -m pipx ensurepath
    
  • enable the ansicolor in Windows terminal for better output experience.
    > reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
    
# via pipx
$ pipx install --force "git+https://github.com/marslo/cr-manager"
# via pip
$ python3 -m pip install cr-manager

# with binary
$ VERSION="$(curl -fsSL https://api.github.com/repos/marslo/cr-manager/releases/latest | jq -r .tag_name)"
# -- linux --
$ curl -fsSL -o cr-manager https://github.com/marslo/cr-manager/releases/download/${VERSION}/cr-manager-linux
# macos
$ curl -fsSL -o cr-manager https://github.com/marslo/cr-manager/releases/download/${VERSION}/cr-manager-macos
# Windows - running in cmd
> powershell -NoProfile -Command "$v=(Invoke-WebRequest -Uri 'https://api.github.com/repos/marslo/cr-manager/releases/latest' -UseBasicParsing | ConvertFrom-Json).tag_name; Invoke-WebRequest -Uri ('https://github.com/marslo/cr-manager/releases/download/'+$v+'/cr-manager.exe') -OutFile 'cr-manager.exe'; Write-Host ('Downloaded '+$v)"

bash completion

automatically detect the OS and install bash completion to the appropriate directory:

  • macos: $(brew --prefix)/etc/bash_completion.d$XDG_DATA_HOME/.local/share~/.bash_completion.d
  • linux: $XDG_DATA_HOME/.local/share~/.bash_completion.d/usr/share/bash-completion/completions/etc/bash_completion.d
# macos
$ cr-manager --install-completion
# or install manually
$ cr-manager --completion | tee "$(brew --prefix)/etc/bash_completion.d/cr-manager"
# linux user folder
$ cr-manager --install-completion
# or install manually
$ cr-manager --completion | tee ~/.bash_completion.d/cr-manager

# linux system folder (requires sudo)
$ sudo cr-manager --install-completion
# or install manually
$ cr-manager --completion | sudo tee /etc/bash_completion.d/cr-manager
# uninstall
test -f ~/.bash_completion.d/cr-manager && rm -rf ~/.bash_completion.d/cr-manager
test -f /etc/bash_completion.d/cr-manager && sudo rm -rf /etc/bash_completion.d/cr-manager
[[ 'Darwin' = "$(uname -s)" ]] && test -f "$(brew --prefix)/etc/bash_completion.d/cr-manager" && rm -rf "$(brew --prefix)/etc/bash_completion.d/cr-manager"

Help Message

$ cr-manager --help
USAGE:
  cr-manager [--add | --check | --delete | --update] [--copyright FILE] [--filetype TYPE] [--recursive]
             [--debug] [--verbose] [--completion] [--install-completion] [--help] [--version]
             FILES ...

A tool to automatically add, update, or delete multi-format copyright headers.

POSITIONAL ARGUMENTS:
  FILES ...                 List of target files or directories to process.

ACTION MODES:
  -a, --add                 Add mode: Adds copyright header to files that are missing it (default).
  -c, --check               Check mode: Verifies file copyright status (match, mismatch, or not found).
  -d, --delete              Delete mode: Removes detected copyright headers from files.
  -u, --update              Update mode: Forces replacement of copyright or adds it if missing.

OPTIONS:
  --copyright FILE          Specify the copyright template file path (default: COPYRIGHT).
  -t, --filetype TYPE       Force override a filetype instead of auto-detection.
                            If provided, displays a formatted preview for that type. Supported: bash, c,
                            c++, cpp, cxx, dockerfile, gradle, groovy, h, hpp, hxx, java, jenkinsfile,
                            python, sh, shell
  -r, --recursive           If FILES includes directories, process their contents recursively.
  --debug                   Debug mode: Preview the result of an action without modifying files.
  --verbose                 Show a detailed processing summary.
  --completion              Print the bash completion script to stdout.
  --install-completion      Install bash completion to the OS-appropriate directory (auto-detected, no
                            root needed by default).
  -h, --help                Show this help message and exit.
  -v, --version             Show program's version number and exit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cr_manager-4.0.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cr_manager-4.0.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file cr_manager-4.0.0.tar.gz.

File metadata

  • Download URL: cr_manager-4.0.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

File hashes

Hashes for cr_manager-4.0.0.tar.gz
Algorithm Hash digest
SHA256 b904720a1315acd7f8a95803a1add5ea19330172b583f425b2a2a58ac3abe8e0
MD5 72d8381b715ee636c5d51a0961aaa31d
BLAKE2b-256 a643ff7738b3911c49c0be7fd9e28f9f6f1ece28f8ce00e77f7b48f8153554c5

See more details on using hashes here.

File details

Details for the file cr_manager-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: cr_manager-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

File hashes

Hashes for cr_manager-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f466cd26d1561a58d438386b55e9b19a6b3e485bcf77b4cc8e02b170453281d5
MD5 0592cdcdcbbd5151dd9e326992c5ef18
BLAKE2b-256 a0623f00cde887e77089d1455c896c1514a6a488c7efadb25c607f931203e418

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page