Update readme, create LICENSE

This commit is contained in:
karlicoss 2020-05-30 08:35:08 +01:00 committed by Dima Gerasimov
parent c85ac1baf6
commit ba4f105d8c
3 changed files with 92 additions and 9 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 karlicoss
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

57
README.org Normal file
View file

@ -0,0 +1,57 @@
#+begin_src python :exports results :results output drawer
import open_in_editor
print(open_in_editor.__doc__)
#+end_src
#+RESULTS:
:results:
This scripts allows opening your text editor from a link on a webpage/within a browser extension via MIME.
See a short [[https://karlicoss.github.io/promnesia-demos/jump_to_editor.webm][demo]].
It handles URIs like:
: editor:///path/to/file:123
: editor:///path/to/file?line=456
See =test_parse_uri= for more examples.
To install (register the MIME handler), run
: python3 open_in_editor.py --install --editor emacs
See =--help= for the list of available editors. If you want to add other editors, the code should be easy to follow.
You can check that it works with
: xdg-open 'editor:///path/to/some/file'
I haven't found any existing/mature scripts for this, *please let me know if you know of any*! I'd be quite happy to support one less script :)
The script was tested on *Linux only*! I'd be happy if someone contributes adjustments for OSX.
:end:
* Usage
#+begin_src bash :exports results :results output verbatim
./open_in_editor.py --help
#+end_src
#+RESULTS:
#+begin_example
usage: open_in_editor.py [-h] [--editor {emacs,vim,gvim,default}] [--install]
[--run-tests]
[uri]
positional arguments:
uri URI to open + optional line number
optional arguments:
-h, --help show this help message and exit
--editor {emacs,vim,gvim,default}
Editor to use. 'default' means using your default GUI
editor (discovered with open/xdg-open)
--install Pass to install (i.g. register MIME in your system)
--run-tests Pass to run unit tests
#+end_example

View file

@ -1,23 +1,28 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
''' '''
This scripts allows triggering opening emacs from a link on a webpage/browser extension via MIME. This scripts allows opening your text editor from a link on a webpage/within a browser extension via MIME.
Handles links like: See a short [[https://karlicoss.github.io/promnesia-demos/jump_to_editor.webm][demo]].
editor:///path/tofile:123 It handles URIs like:
See test_parse_uri for more examples. : editor:///path/to/file:123
: editor:///path/to/file?line=456
See =test_parse_uri= for more examples.
To install (register the MIME handler), run To install (register the MIME handler), run
python3 open-in-editor --editor emacs --install : python3 open_in_editor.py --install --editor emacs
See --help for the list of available editors. If you want to add other editors, the code should be easy to follow. See =--help= for the list of available editors. If you want to add other editors, the code should be easy to follow.
You can check that it works with You can check that it works with
xdg-open 'editor:///path/to/some/file' : xdg-open 'editor:///path/to/some/file'
I haven't found any existing/mature scripts for this, please let me know if you know of any! I'd be happy to support one less script. I haven't found any existing/mature scripts for this, *please let me know if you know of any*! I'd be quite happy to support one less script :)
The script was tested on *Linux only*! I'd be happy if someone contributes adjustments for OSX.
''' '''
# TODO make it editor-agnostic? although supporting line numbers will be trickier # TODO make it editor-agnostic? although supporting line numbers will be trickier
@ -111,7 +116,7 @@ Terminal=false
MimeType=x-scheme-handler/{PROTOCOL_NAME}; MimeType=x-scheme-handler/{PROTOCOL_NAME};
""".strip() """.strip()
with tempfile.TemporaryDirectory() as td: with tempfile.TemporaryDirectory() as td:
pp = Path(td) / 'open-in-editor.desktop' pp = Path(td) / 'open_in_editor.desktop'
pp.write_text(CONTENT) pp.write_text(CONTENT)
check_call(['desktop-file-validate', str(pp)]) check_call(['desktop-file-validate', str(pp)])
dfile = Path('~/.local/share/applications').expanduser() dfile = Path('~/.local/share/applications').expanduser()