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.
- 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.
- Python 3.7+
- OpenAI Python library
- dotenv for optional environment configuration
- Clone the repository:
git clone git@github.com:demondehellis/corrector.git
cd corrector
- Install the required dependencies:
pip install -r requirements.txt
- 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:
OPENAI_API_KEY=your-api-key
CORRECTOR_MODEL=gpt-4o-mini # Optional, default model is gpt-4o-mini
To correct grammar and punctuation in an entire file:
python corrector.py input.txt
To save the corrected content to a specific file:
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:
python corrector.py input.txt --lines 1:5 --output output.txt
To use this script as an external tool, follow these steps:
- Open your IDE and navigate to
Preferences
>Tools
>External Tools
. - Click the
+
button to add a new tool. - Fill in the following details:
- Name: Grammar Corrector
- Program: Path to your Python executable (e.g.,
/opt/homebrew/bin/python3.11
). - Arguments:
/path/to/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.
- Click
OK
to save the configuration.
- 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
.
This project is licensed under the MIT License.