wedit is a smart command-line utility to reliably open files in your preferred editor, ensuring the calling process waits for editing to complete.
It intelligently honors $VISUAL and $EDITOR, automatically applies the correct "wait" flags for various editors, provides sane defaults, offers interactive configuration, and gracefully falls back to available alternatives.
Developers often need a consistent way to open files from scripts (e.g., Git hooks, CLI tools) and have the script pause until the editor is closed. Existing solutions can be inconsistent:
- Custom wrappers might only support a few editors.
- System-provided scripts (like
sensible-editor) might not handle "wait" flags automatically. - Manually configuring aliases or environment variables (e.g.,
EDITOR='code --wait') requires per-editor knowledge and setup.
wedit aims to be a single, robust, and user-friendly solution for this common task.
- Environment Variable Aware: Honors
$VISUALand$EDITORenvironment variables. - Automatic Wait Flags: Intelligently detects and applies the correct "wait" flags for popular GUI editors (e.g.,
code --wait,subl --wait,gedit --wait,kate --block). - Smart Fallback Hierarchy:
$VISUAL$EDITOR- User configuration (
~/.weditrc) - System 'editor' alternative (on Linux via
update-alternatives) - First available editor from a built-in list
- Interactive prompt (on first run or if no editor is found)
- Fallback to
viornanoif available.
- Interactive Configuration: Run
wedit -cto choose and save your preferred editor from a list of detected ones. - Recursion Safe: Prevents accidental infinite loops if
wedititself is set as$EDITOR. - Lightweight & Portable: A single Bash script designed to work on Linux and macOS with minimal dependencies.
- Editor Discovery: Can list detected editors with
wedit -l. - Flexible Control: Options to force or disable wait behavior (
-w,-n).
wedit has built-in support for detecting and managing wait flags for the following editors:
| Editor | Detection Command | Wait Flag(s) | Notes |
|---|---|---|---|
code |
command -v code |
--wait |
VS Code CLI |
subl |
command -v subl |
--wait |
Sublime Text |
atom |
command -v atom |
--wait |
Atom |
gedit |
command -v gedit |
--wait |
GNOME Text Editor |
kate |
command -v kate |
--block |
KDE Advanced Text Editor |
gvim |
command -v gvim |
--remote-wait-silent |
GUI Vim |
vim, nvim |
command -v vim |
none (TTY blocks) | Terminal editors block by default |
nano |
command -v nano |
none | Terminal editor |
emacsclient |
command -v emacsclient |
--no-wait |
Blocks when file is saved via server-edit hook |
vi |
command -v vi |
none (TTY blocks) | Common fallback terminal editor |
Terminal-based editors (like Vim, Nano, Vi) naturally block the calling process, so no explicit wait flags are needed for them unless overridden.
You can download the wedit script or pre-built packages (if available) from the GitHub Releases page.
-
Script: Download
wedit.sh, make it executable, and place it in your$PATH.VERSION="v0.1.0" # Replace with the latest version curl -Lo wedit https://github.com/ngirard/wedit/releases/download/${VERSION}/wedit.sh chmod +x wedit sudo mv wedit /usr/local/bin/wedit
-
Packages (.deb, .rpm): If
.debor.rpmpackages are provided, download the appropriate file and install using your system's package manager. For example, for a.debfile:# Example for .deb package # sudo dpkg -i wedit_${VERSION}_amd64.deb # sudo apt-get install -f # To install dependencies if any
(The
nfpm.yamlsuggests packages might be generated, installing to/usr/local/bin/wedit.)
Clone the repository or download src/wedit.sh:
git clone https://github.com/ngirard/wedit.git
cd wedit
sudo cp src/wedit.sh /usr/local/bin/wedit
sudo chmod +x /usr/local/bin/weditwedit [options] [--] <file> [<file>...]
wedit [options]
Common Operations:
-
Edit a file:
wedit myfile.txt wedit notes.md config.yaml
-
Configure your preferred editor:
weditwill guide you through selecting an editor from those it detects on your system. The choice is saved to~/.weditrc.wedit -c
After selection,
weditwill open~/.weditrcwith the newly chosen editor. -
List detected editors:
wedit -l
-
Get help:
wedit -h wedit --help
Options:
-h, --help: Show the help message and exit.-c, --config: Configure the preferred editor interactively. Saves to~/.weditrcand then opens this file.-l, --list: List all detected known editors and their properties.-n, --no-wait: Override default wait behavior; do not add wait flags for GUI editors.-w, --wait: Force waiting behavior. This is default for GUI editors with wait flags and all TTY editors. Primarily ensures GUI wait flags are used.--: Signals the end of options; all subsequent arguments are treated as file names.
Example Use Case (Git commit hook):
Set wedit as your Git editor to ensure Git waits for your message:
git config --global core.editor "wedit"wedit determines which editor to use based on the following hierarchy:
$VISUALEnvironment Variable: If set, its value is used.$EDITOREnvironment Variable: If$VISUALis not set and$EDITORis, its value is used.- User Configuration File:
~/.weditrc(Primary)~/.selected_editor(Fallback for reading, compatible with Debian'sselect-editor) The file should contain a line like:SELECTED_EDITOR="your-editor-command --optional-args"You can create/manage this file usingwedit -c.
- System 'editor' Alternative: On Linux systems using
update-alternatives,weditwill try to use the system-configurededitor. - Built-in List of Known Editors:
weditscans for known editors in your$PATH(see Supported Editors). - Interactive Prompt: If no editor is found through the above methods and no configuration exists,
weditwill prompt you to select an editor. This choice is then saved to~/.weditrcfor future use. - Final Fallback: If all else fails,
weditwill attempt to useviornanoif they are available. - Error: If no editor can be found,
weditwill exit with an error.
This project uses just (a command runner) for common development tasks. See the justfile.
Prerequisites:
- Bash
shellcheck(for lintingsrc/wedit.sh)just(optional, but recommended for usingjustfilecommands)
Common just commands:
just lint: Check the script withshellcheck.just test: Run all tests (requires test suite to be set up in./tests/).just test-one <name>: Run a specific test file./tests/test_<name>.sh.just release: (For maintainers) Executes the release script.
Contributions are welcome! Whether it's bug reports, feature suggestions, or pull requests:
- Issues: Please check for existing issues before opening a new one. Provide as much detail as possible.
- Pull Requests:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes. Ensure
shellcheckpasses (just lint). - Add tests if applicable.
- Commit your changes with clear messages.
- Push to your fork and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Copyright (c) 2025, Nicolas Girard