View on GitHub

cat-clipboard-launcher

cat-clipboard-launcher

cat-clipboard-launcher

備忘、用途、事例

Installation

pip install -r requirements.txt

Quick Start Guide

cat-clipboard-launcherを最速で使い始める方法:

1. 必要最小限の設定ファイルを作成

プロジェクトのルートディレクトリ(src/launcher.pyと同じ階層)にconfig.tomlを作成し、たった1行追加するだけ:

patterns = [{name = "テキストエディタで開く", regex = ".*", command = "notepad.exe {CLIPBOARD_FILE}"}]

これで設定完了です!

2. 使ってみる

  1. 何かテキストをクリップボードにコピーする
  2. ランチャーを起動する:
    python src/launcher.py --config-filename config.toml
    
  3. aキーを押してパターンを選択
  4. メモ帳が起動してクリップボードの内容が表示されます

注意事項:

より詳しい設定

複数のパターンを追加して、クリップボードの内容に応じて自動判別できます:

# clipboard_temp_fileは省略可(デフォルト:./clipboard_content.txt)

[[patterns]]
name = "URL"
regex = "^https?://.*"
command = "start chrome.exe {CLIPBOARD_FILE}"

[[patterns]]
name = "GitHub Issue"
regex = "#\\d+"
command = "notepad.exe {CLIPBOARD_FILE}"

Configuration

Create or edit config.toml for your specific needs. You can use examples/config.toml as a reference template:

# Path where clipboard content will be saved temporarily
# OPTIONAL: Defaults to "./clipboard_content.txt" (in current directory)
clipboard_temp_file = "./clipboard_content.txt"

# Pattern definitions
[[patterns]]
name = "URL"
regex = "^https?://.*"
command = "start chrome.exe {CLIPBOARD_FILE}"

[[patterns]]
name = "GitHub Issue"
regex = "#\\d+"
command = "notepad.exe {CLIPBOARD_FILE}"

[[patterns]]
name = "Text Filter"
regex = "^FILTER:"
command = "python.exe filter.py --input {CLIPBOARD_FILE} --output {CLIPBOARD_FILE}.result"
output_file = "{CLIPBOARD_FILE}.result"
write_output_to_clipboard = true  # Output will be written back to clipboard

Configuration Fields

Running the Launcher

# The --config-filename argument is required
python src/launcher.py --config-filename path/to/config.toml

# Example with absolute path
python src/launcher.py --config-filename C:/Users/username/config.toml

# Example with relative path
python src/launcher.py --config-filename ./config.toml

Note: The --config-filename argument is required. There is no default configuration file.

Usage Flow

  1. Copy text to clipboard
  2. Run the launcher
  3. The launcher will:
    • Display first 3 lines of clipboard content (80 chars max per line)
    • Show matched patterns (a-z)
    • Wait for your choice
  4. Press a-z to select a pattern, or ESC to exit
  5. Selected command will be executed

Example Workflow

  1. Copy https://github.com/example/repo to clipboard
  2. Run launcher
  3. See “URL” pattern matched
  4. Press ‘a’ to open in browser
  5. Chrome opens with the clipboard content

Testing

Run tests with:

pytest tests/test_launcher.py -v

Development

Format and lint code:

# Format code
ruff format src/ tests/

# Fix linting issues
ruff check --fix src/ tests/