Index

Book filename generator

Generate consistent AUTHOR-YEAR-Title filename from the terminal, automatically copied to your clipboard.

What it does

Prompts for an author name, year, and title, then formats them into a citation key like:

CAMUS-1942-LeMytheDeSisyphe

Accents are stripped, the author is uppercased, and the title is converted to CamelCase. The result is printed and copied to the clipboard automatically via pbcopy.

The script

Save this as ~/scripts/citekey.py (or any path you prefer):

import sys, unicodedata, re, subprocess

def remove_accents(text):
    return ''.join(
        c for c in unicodedata.normalize('NFD', text)
        if unicodedata.category(c) != 'Mn'
    )

def to_camel(title):
    title = remove_accents(title)
    words = re.split(r"[^a-zA-Z0-9]+", title)
    return ''.join(w.capitalize() for w in words if w)

def to_author(name):
    name = remove_accents(name)
    name = re.sub(r"[^a-zA-Z0-9]", "", name)
    return name.upper()

print("Author name:  ", end="", flush=True)
author = input().strip()
print("Year:         ", end="", flush=True)
year = input().strip()
print("Title:        ", end="", flush=True)
title = input().strip()

result = f"{to_author(author)}-{year}-{to_camel(title)}"
print(f"\n{result}")

subprocess.run("pbcopy", input=result.encode(), check=True)
print("(copied to clipboard)")

How it works

The key is formatted as AUTHOR-YEAR-CamelCaseTitle.

Part Rule Example input Output
Author Strip accents, remove non-alphanumeric, uppercase Simone de Beauvoir SIMONEDEBEAUVOIR
Year Used as-is 1949 1949
Title Strip accents, split on non-alphanumeric, CamelCase each word Le deuxième sexe LeDeuxiemeSexe

Accents are removed by decomposing characters into their base letter and combining mark (NFD normalization), then discarding any character in the Mn (Mark, Nonspacing) Unicode category.

Example

Author name:   Albert Camus
Year:          1942
Title:         Le Mythe de Sisyphe

CAMUS-1942-LeMytheDeSisyphe
(copied to clipboard)

Add to ~/.zshrc

Add a citekey function to your ~/.zshrc so you can call it from anywhere:

citekey() {
  python3 ~/scripts/citekey.py
}

Or as a one-liner alias if you prefer:

alias citekey="python3 ~/scripts/citekey.py"

Then reload your shell:

source ~/.zshrc

Run it with:

citekey

Requirements

Last updated: 19-05-2026 at 08:39