A terminal-based text editor designed for developers, featuring automatic syntax validation, PATH search, and safe file operations. Pure bash implementation with minimal external dependencies.
- Automatic editor detection - Finds and uses available text editors (joe, nano, vim, vi, etc.)
- PATH search - Automatically searches PATH for executables when file not found locally
- Multi-format validation - Built-in syntax validation for JSON, YAML, XML, Python, Shell scripts, and more
- Safe file editing - Atomic file operations with temporary file handling
- Binary file protection - Prevents accidental editing of binary files
- Symlink resolution - Automatically resolves symbolic links to edit actual files
- Shellcheck integration - Optional shell script analysis
- Line number support - Jump directly to specific line numbers
- Minimal dependencies - Core functionality requires only bash and standard Unix tools
# Clone the repository
git clone https://github.com/Open-Technology-Foundation/editfile
cd editfile
# Make the script executable
chmod +x editfile
# Optional: Link to a directory in your PATH
sudo ln -s $(pwd)/editfile /usr/local/bin/editfile
editfile [OPTIONS] filename
-n
,--no-validate
- Skip validation-l
,--line LINE
- Start editing at specified line number-s
,--shellcheck
- Run shellcheck on shell scripts after editing-V
,--version
- Show version information and exit-h
,--help
- Display help message
# Edit Python file with validation
editfile script.py
# Edit shell script without validation
editfile -n deploy.sh
# Edit JSON file starting at line 42
editfile -l 42 config.json
# Edit shell script and run shellcheck
editfile -s install.sh
# Edit an executable in your PATH (e.g., a custom script)
editfile cln
# Edit system command/script (if text file)
editfile backup-script
# Create a new file (will prompt for confirmation)
editfile newfile.txt
File type detection is performed using:
- File extension
- Shebang line (#!)
- Content analysis with
file
command
File Type | Extensions | Validator |
---|---|---|
JSON | .json, .jsonld | jq or python3 |
YAML | .yaml, .yml | yamllint or python3 |
XML | .xml, .xsl, .xslt, .svg | xmllint or python3 |
HTML | .html, .htm, .xhtml | tidy |
Python | .py, .pyw, .pyi | python3 |
Shell | .sh, .bash, .zsh, .ksh | bash -n, shellcheck |
PHP | .php, .phtml | php -l |
INI | .ini, .conf, .cfg | awk |
CSV | .csv, .tsv | awk |
TOML | .toml, .tml | python3 with tomli/toml |
Markdown | .md, .markdown | (no validation) |
- bash 4.0+
- Standard Unix tools (grep, awk, sed, od, file)
- A text editor (nano, vim, vi, or any editor)
Install these for enhanced validation capabilities:
# Ubuntu/Debian
sudo apt install jq yamllint xmllint shellcheck php-cli tidy
# macOS with Homebrew
brew install jq yamllint libxml2 shellcheck php tidy-html5
# Fedora/RHEL
sudo dnf install jq yamllint libxml2 ShellCheck php-cli tidy
For Python-based validation:
# YAML support
pip install PyYAML
# TOML support
pip install tomli # or toml for older Python
The script selects editors in this priority:
$EDITOR
environment variable- Search for installed editors in order: joe, nano, vim, vi, mcedit, ne, micro, emacs, jed, gedit
To set a preferred editor:
export EDITOR=vim
- File Resolution - Searches for file locally, then in PATH if not found
- Binary Check - Verifies file is text, not binary executable
- Type Detection - Identifies file type from extension, shebang, or content
- Temporary File - Creates a temporary copy for editing (atomic operations)
- Editor Launch - Opens the file in detected/configured editor
- Validation - Runs appropriate validator after editing (if enabled)
- Save or Retry - On validation failure, offers options to edit again, save anyway, or quit
- Atomic Replace - Moves temp file to final location
When a filename without path separators is not found locally, editfile will:
- Search for the command in your PATH using
command -v
- Resolve any symbolic links to find the actual file
- Check if the file is text (not binary)
- Prompt to edit if it's a text file
- Show an error if it's a binary executable
This is particularly useful for quickly editing scripts and commands in development environments without needing to know their full path.
- Binary files - Refuses to edit binary files
- Permissions - Checks write permissions before editing
- Validation failures - Interactive prompt with options to retry or force save
- Missing validators - Gracefully continues with warnings when validators aren't installed
EDITOR
- Preferred text editor to use
The script follows the Bash Coding Standard with:
- Strict error handling (
set -euo pipefail
) - Proper variable declarations and scoping
- Consistent 2-space indentation
- Comprehensive trap handling
- ShellCheck compliance
This project is licensed under the GNU General Public License v3.0 - see the GNU GPL v3 for details.
Contributions are welcome! Please ensure:
- Code follows the bash coding standard
- ShellCheck passes without errors
- Validation tests pass
- Documentation is updated as needed
Run the included test suite:
./test_validation.sh
The test suite validates:
- JSON, YAML, Python, Shell script validation
- Invalid file detection
- Editor detection fallback
- Command-line argument parsing