203 lines
4.2 KiB
Markdown
203 lines
4.2 KiB
Markdown
# unique
|
|
|
|
A small but practical command-line utility for creating safe, unique file and directory names.
|
|
|
|
When scripts, backups, content pipelines, or file-based workflows need to create or rename paths
|
|
without collisions, `unique` appends a timestamp-, UUID-, or entropy-based suffix to keep names
|
|
distinct, readable, and easy to trace.
|
|
|
|
## Why use unique?
|
|
|
|
File naming collisions are a recurring problem in scripting, automation, backups, content pipelines,
|
|
and content authoring workflows. `unique` gives you a simple interface to:
|
|
|
|
- create a new file or directory with a guaranteed unique name
|
|
- rename an existing path to have a unique name
|
|
- duplicate a file while preserving its original contents under a fresh name
|
|
- choose the suffix generation method that best fits your workflow
|
|
|
|
## Features
|
|
|
|
- Create files or directories with unique names
|
|
- Rename existing files or folders safely
|
|
- Duplicate files with a unique derivative name
|
|
- Multiple suffix strategies:
|
|
- `datetime`
|
|
- `epoch`
|
|
- `uuid`
|
|
- `uuid7`
|
|
- `uuid-b36`
|
|
- `uuid7-b36`
|
|
- Python-based CLI design for simple automation and scripting
|
|
|
|
## Documentation
|
|
|
|
- [Build from Source](docs/build-from-source.md) — set up the project and produce a distributable build.
|
|
- [Using unique](usage.md) — learn the CLI commands and examples.
|
|
|
|
## Installation
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3
|
|
- `pip`
|
|
|
|
### Set up a virtual environment
|
|
|
|
```bash
|
|
python3 -m venv .venv
|
|
source .venv/bin/activate
|
|
```
|
|
|
|
### Install dependencies
|
|
|
|
```bash
|
|
pip install "git+https://rprime.indroneel.co/termhole/scott.git"
|
|
pip install uuid6
|
|
```
|
|
|
|
### Install the project
|
|
|
|
```bash
|
|
pip install -e .
|
|
```
|
|
|
|
You can then invoke the CLI as:
|
|
|
|
```bash
|
|
unique --help
|
|
```
|
|
|
|
## Usage
|
|
|
|
The CLI is organized around a small set of commands.
|
|
|
|
### Create a unique file
|
|
|
|
```bash
|
|
unique create --file notes.txt
|
|
```
|
|
|
|
Example result:
|
|
|
|
```text
|
|
notes-20260916-153425.txt
|
|
```
|
|
|
|
### Create a unique directory
|
|
|
|
```bash
|
|
unique create --dir project
|
|
```
|
|
|
|
Example result:
|
|
|
|
```text
|
|
project-20260916-153425
|
|
```
|
|
|
|
### Rename an existing file or directory
|
|
|
|
```bash
|
|
unique touch report.md
|
|
```
|
|
|
|
This appends a generated suffix to the original path instead of overwriting an existing file.
|
|
|
|
### Duplicate a file with a unique name
|
|
|
|
```bash
|
|
unique duplicate ./archive.tar.gz
|
|
```
|
|
|
|
Example result:
|
|
|
|
```text
|
|
archive-20260916-153425.tar.gz
|
|
```
|
|
|
|
## Suffix methods
|
|
|
|
You can control the suffix algorithm with the `--method` option:
|
|
|
|
```bash
|
|
unique create --file draft.txt --method uuid7
|
|
```
|
|
|
|
Available methods:
|
|
|
|
- `datetime` — current date and time
|
|
- `epoch` — Unix timestamp in milliseconds
|
|
- `uuid` — UUID v4
|
|
- `uuid7` — UUID v7
|
|
- `uuid-b36` — base36 UUID representation
|
|
- `uuid7-b36` — base36 UUID v7 representation
|
|
|
|
## Command reference
|
|
|
|
### `unique create`
|
|
|
|
Create a file or directory with a unique name.
|
|
|
|
```bash
|
|
unique create PATH --file|--dir [--method METHOD]
|
|
```
|
|
|
|
### `unique touch`
|
|
|
|
Rename an existing file or directory to a unique variant.
|
|
|
|
```bash
|
|
unique touch PATH [--method METHOD]
|
|
```
|
|
|
|
### `unique duplicate`
|
|
|
|
Create a copy of an existing file with a unique name.
|
|
|
|
```bash
|
|
unique duplicate PATH [--method METHOD]
|
|
```
|
|
|
|
## Examples
|
|
|
|
```bash
|
|
# Create a unique file using a UUID v7 suffix
|
|
unique create --file draft.md --method uuid7
|
|
|
|
# Create a unique directory using the current timestamp
|
|
unique create --dir content --method datetime
|
|
|
|
# Rename an existing file to a unique version
|
|
unique touch ./notes.txt --method epoch
|
|
|
|
# Duplicate a file without clobbering the original
|
|
unique duplicate ./backup.db --method uuid-b36
|
|
```
|
|
|
|
## Project layout
|
|
|
|
```text
|
|
unique/
|
|
├── LICENSE
|
|
├── README.md
|
|
├── pyproject.toml
|
|
├── unique.spec
|
|
├── src/
|
|
│ └── unique/
|
|
│ ├── commands/
|
|
│ ├── lib/
|
|
│ └── main.py
|
|
└── .venv/
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the terms of the repository license. See [LICENSE](LICENSE) for details.
|
|
|
|
## Notes
|
|
|
|
This project is intentionally compact and script-friendly: it focuses on one task well—creating unique names for paths—while leaving room for automation in shell scripts, build tooling, and content workflows.
|
|
|
|
If you want to package it into a standalone executable, the repository includes a PyInstaller spec file at [unique.spec](unique.spec).
|