Terminal-based text editor wrapper providing safe file editing with built-in validation for multiple file formats. Designed for system administrators and developers who need reliable file editing with syntax checking.
- 🔍 Comprehensive syntax validation for multiple file formats
- 🛡️ Safe editing with robust temporary file handling
- 🎯 Intelligent editor detection
- 📝 Line number targeting support
- 🔒 Enhanced binary file detection and protection
- 🔄 Advanced path resolution and symlink handling
- ⚡ Smart executable file detection with safety prompts
- 🐚 Improved shellcheck integration (only for shell scripts)
- 🌈 Colorized output with graceful fallback
- Python (.py, .pyw, .pyi)
- PHP (.php, .phtml, .php3-7)
- Shell Scripts (.sh, .bash, .zsh, .ksh)
- JSON/JSONLD (.json, .jsonld)
- YAML (.yml, .yaml)
- XML/XSLT/SVG (.xml, .xsl, .xslt, .svg)
- HTML (.html, .htm, .xhtml)
- Markdown (.md, .markdown, .mdown)
- TOML (.toml, .tml)
- INI/Config (.ini, .conf, .cfg, .config)
- CSV/TSV (.csv, .tsv)
- Clone the repository:
git clone https://github.com/Open-Technology-Foundation/edit_file
cd edit_file
- Install required Python packages:
pip install -r requirements.txt
- Make scripts executable:
chmod +x edit_file.py filetype.py shellcheckr.py
- Optional: Create system-wide symlink:
sudo ln -s $(pwd)/edit_file.py /usr/local/bin/edit_file
Basic usage:
edit_file filename
Options:
edit_file [-n] [-l LINE] [-s] filename
Options:
-n, --no-validate Skip validation
-l, --line LINE Start editing at specified line number
-s, --shellcheck Run shellcheck on shell scripts after editing
Edit a Python script with validation:
edit_file script.py
Edit YAML file starting at line 50:
edit_file -l 50 config.yaml
Edit shell script with shellcheck:
edit_file -s deploy.sh
Edit without validation:
edit_file -n data.json
The script selects editors in this priority:
$EDITOR
environment variable- Available system editors in order:
- joe
- nano
- vim
- vi
- mcedit
- ne
- micro
- emacs
- jed
- gedit
- Python 3.12+
- PyYAML
- colorama (optional, for colored output)
- shellcheck (shell script validation)
- yamllint (YAML validation)
- php-cli (PHP validation)
- html5lib (HTML validation)
- mdformat (Markdown validation)
- tomli or toml (TOML validation)
# Core dependencies
sudo apt install python3-yaml python3-colorama
# Optional validators
sudo apt install shellcheck yamllint php-cli python3-html5lib python3-mdformat python3-tomli
- ✅ Fixed shellcheck usage: Now only runs on shell scripts
- ✅ Improved error handling: More robust error handling throughout the code
- ✅ Enhanced file type detection: Better detection of file types
- ✅ Better temporary file management: Using Python's tempfile module for safer handling
- ✅ Added colorama fallback: Colorama is now optional with graceful degradation
- ✅ Improved validation: Enhanced validation functions with better error messages
- ✅ Fixed editor preferences
- ✅ Improved code organization: Better structured with clearer function responsibilities
.
├── edit_file.py # Main editor script
├── filetype.py # File type detection
├── shellcheckr.py # Shell script validator
├── requirements.txt # Python dependencies
└── README.md # Documentation
The script provides validation for various file types:
File Type | Validation Method |
---|---|
Python | Python compiler |
PHP | php -l |
Shell | bash -n + shellcheck |
JSON | json.load |
YAML | yamllint + PyYAML |
XML | ElementTree |
HTML | html5lib |
Markdown | mdformat |
TOML | tomli/toml |
INI | configparser |
CSV | csv module |
Contributions welcome! Please feel free to submit pull requests.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Gary Dean - garydean@yatti.id