https://github.com/demondehellis/corrector
External Tool for JetBrains IDEs to correct grammar and punctuation in selected lines.
https://github.com/demondehellis/corrector
blogging cli external-tools gpt gpt-4 grammar ide intellij-idea intellij-plugin markdown punctuation spellchecker writting
Last synced: about 1 month ago
JSON representation
External Tool for JetBrains IDEs to correct grammar and punctuation in selected lines.
- Host: GitHub
- URL: https://github.com/demondehellis/corrector
- Owner: demondehellis
- Created: 2024-02-17T08:38:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T08:16:35.000Z (over 1 year ago)
- Last Synced: 2025-02-04T09:23:34.269Z (over 1 year ago)
- Topics: blogging, cli, external-tools, gpt, gpt-4, grammar, ide, intellij-idea, intellij-plugin, markdown, punctuation, spellchecker, writting
- Language: Python
- Homepage: https://github.com/demondehellis/corrector
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# External Tool for Grammar and Punctuation Correction
## Overview
This simple script is designed for use as an **external tool** in JetBrains IDEs like **IntelliJ IDEA**, **PhpStorm**, and **PyCharm**, enabling quick text corrections on **selected lines** directly from the context menu or through keyboard shortcuts.

## Features
- **Correction of selected lines**: Select lines in your IDE and run the tool to correct grammar and punctuation.
- **Configurable settings**: Adjust the model and prompt via environment variables or shell configuration files.
## Requirements
- Python 3.7+
- OpenAI Python library
- dotenv for optional environment configuration
## Installation
1. Clone the repository:
```bash
git clone git@github.com:demondehellis/corrector.git
cd corrector
```
2. Install the required dependencies:
```bash
python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt
```
3. Configure environment variables:
You can set environment variables in your `.bashrc`, `.zshrc`, or any shell configuration file. Optionally, you can also create a `.env` file with the following variables:
```dotenv
OPENAI_API_KEY=your-api-key
CORRECTOR_MODEL=gpt-4o-mini # Optional, default model is gpt-4o-mini
```
## Basic Usage
To correct grammar and punctuation in an entire file:
```bash
/path/to/corrector/venv/bin/python corrector.py input.txt
```
To save the corrected content to a specific file:
```bash
/path/to/corrector/venv/bin/python corrector.py input.txt --output output.txt
```
To correct specific lines from the input file (e.g., lines 1 to 5) and save the result:
```bash
/path/to/corrector/venv/bin/python corrector.py input.txt --lines 1:5 --output output.txt
```
## Using as an External Tool in JetBrains IDEs
To use this script as an external tool, follow these steps:
1. Open your IDE and navigate to `Preferences` > `Tools` > `External Tools`.
2. Click the `+` button to add a new tool.
3. Fill in the following details:
- **Name**: Grammar Corrector
- **Program**: Path to your Python executable (e.g., `/path/to/corrector/venv/bin/python`).
- **Arguments**: `/path/to/corrector/corrector.py $FilePath$ --lines $SelectionStartLine$:$SelectionEndLine$`
- **Working Directory**: `$ProjectFileDir$`
- Enable `Synchronize files after execution`.
- (Optional) Check `Open console for tool output` to view the output or any errors.
4. Click `OK` to save the configuration.

### Tips for Quick Access
- **Keyboard Shortcuts**: Assign a custom keyboard shortcut to the external tool for instant access. Go to `Preferences` > `Keymap`, search for your external tool, and set your desired shortcut.
- **Add to Menus or Toolbars**: For even quicker access, add the external tool to your IDE’s menu or toolbar by right-clicking on the menu or toolbar and selecting `Customize Menus and Toolbars`.
## License
This project is licensed under the MIT License.