Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metov/openeditor
Edit files with your $EDITOR, like git commit does.
https://github.com/metov/openeditor
command-line editor hacktoberfest hacktoberfest2021 interactive python
Last synced: 14 days ago
JSON representation
Edit files with your $EDITOR, like git commit does.
- Host: GitHub
- URL: https://github.com/metov/openeditor
- Owner: metov
- License: mit
- Created: 2021-04-22T03:45:47.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-24T05:31:36.000Z (over 3 years ago)
- Last Synced: 2024-10-04T21:16:09.878Z (about 1 month ago)
- Topics: command-line, editor, hacktoberfest, hacktoberfest2021, interactive, python
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# `openeditor`
Edit files with your `$EDITOR`, like git commit does.## Usage
Install with: `pip install openeditor````
# Let user edit file
s = openeditor.edit_file("path/to/my/file.txt")
print("The file now contains:\n" + s)# Use a temp file
s = openeditor.edit_file(
"# Please edit this file, save and close editor when done",
"path/to/my/file.txt"
)
print("The file now contains:\n" + s)
```The editor is obtained from, in order of precedence:
* `$VISUAL`
* `$EDITOR`If neither of these provide a useful editor, an exception will be thrown.
## Limitations
`openeditor` expects an editor string similar to `EDITOR=cmd` such that:1. `cmd file.txt` (filename as the final argument) is a correct way of editing `file.txt`.
2. `cmd` is not too complex. Simple things like space-separated flags (eg. `EDITOR="vim -n"`) are fine but advanced shell magic may break.If your `cmd` **does** need to be more complex, one possible workaround is to write a wrapper script that presents a compatible command-line interface to `openeditor` and invokes the full command as appopriate.