Closed terinjokes closed 5 years ago
As is noted at https://sw.kovidgoyal.net/kitty/kittens/custom.html
you need to use
map ctrl+k kitten mykitten.py arg1 arg2
i.e. the kitten is meant to be launched from within kitty using a mapping, not as a standalone program. If you wish to create a standalone python script to run with kitty you can use
kitty +launch myscript.py
@kovidgoyal Is it possible to be a kitten invokeable by a binding and from the kitten subcommand?
There is not much point in invoking a kitten via +kitten -- kittens are meant to integrate with kitty, which they cannot if they are run as independent processes. As I said you can run your kitten using kitty +launch directly as a normal python script, but one where you can import anything from the kitty package.
I'm really confused now. How are kittens like icat
, diff
, ssh
, and clipboard
different than ones I might write myself?
They are not different, I just happened to overload the kittens system to write standalone programs (gives them a name and an integration point in the documentation and a way to run them easily without needing to deal with paths).
You can do the same thing, just use +launch instead of +kitten.
In fact you can run the builtin kittens that way as well, for example:
kitty +launch /path/to/ssh/kitten/main.py
That doesn't seem to do what I expect.
$ kitty +launch ~/.config/kitty/mykitten.py
$ kitty +launch /usr/lib/kitty/kittens/unicode_input/main.py
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/bin/../lib/kitty/__main__.py", line 117, in <module>
main()
File "/usr/bin/../lib/kitty/__main__.py", line 108, in main
namespaced(['+', first_arg[1:]] + sys.argv[2:])
File "/usr/bin/../lib/kitty/__main__.py", line 68, in namespaced
func(args[1:])
File "/usr/bin/../lib/kitty/__main__.py", line 51, in launch
runpy.run_path(exe, run_name='__main__')
File "/usr/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/kitty/kittens/unicode_input/main.py", line 21, in <module>
from ..tui.line_edit import LineEdit
ImportError: attempted relative import with no known parent package
Otherwise, I think I understand the disconnect. I was expecting behavior similar to the builtin programs. I'll get back to writing my kitten now.
You have to add
if __name__ == '__main__':
main(sys.argv)
to the bottom of your kitten.
And just to reduce confusion for anyone else in the future, I have made it possible to run custom kittens via +kitten.
@kovidgoyal Thanks. Knowing that (previously) those were overloaded onto +kitten
explains where I was being confused.
Sorry if I didn't explain that as well in the initial post.
My configuration file for Kitty is located in
~/.config/kitty
. I've created amykitten.py
in the same directory, but I get an error that the kitten isn't found.I'm not sure what I'm doing wrong.