kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.15k stars 972 forks source link

Placing custom kittens in ~/.config/kitty/kittens #732

Closed maximbaz closed 6 years ago

maximbaz commented 6 years ago

I've just written my first kitten! Very happy that terminal is so extensible, and writing it was relatively simple, I just referred to unicode_input kitten as an example.

My question is: it seems I can only place my kitten in /usr/lib/kitty/kittens folder, but I would like to keep it in home dir. Can kitty also load kittens from ~/.config/kitty/kittens folder if it exists?

kovidgoyal commented 6 years ago

Congratulations :) It's been a while since I looked at it, but I think the kitten loading system supports that already, just in the ~/.config/kitty folder though, no sub-folder needed. IIRC You can also use an absolute path. So if your kitten is in mykitten.py put it in ~/.config/kitty and use the name "mykitten.py" as the kitten name. or put it in /some/folder/mykitten.py and use "/some/folder/mykitten.py" as the kitten name.

If you have any trouble, let me know.

maximbaz commented 6 years ago

That was the trick, I tried that before opening an issue but was using

map ctrl+shift+y  run_kitten text mykitten

But I should have specified the extension too, i.e.

map ctrl+shift+y  run_kitten text mykitten.py

Then it works. Specifying the absolute path works too. Thanks :)

kovidgoyal commented 6 years ago

Note you dont need run_kitten, just

kitten mykitten.py

is enough.

maximbaz commented 6 years ago

Yep, just seen that, already updated - thanks :)

kovidgoyal commented 6 years ago

At some point I have to document the process for creating your own kittens and the kitty terminal UI package that you can use to implement them. If only a day had more hours :)

net commented 6 years ago

@kovidgoyal where should I put kittens on macOS so that I can call them with kitty kitten <kitten>?

I tried ~/.config/kitty, however that only seems to work with map <mapping> kitten <kitten>. kitty kitten <my kitten> gives me No kitten named <my kitten> for all the various names and paths I could think of, and kitty kitten asks me to choose from an empty list.

I'd like to pass the current directory to my kitten's main function. I'm not sure how or if I can do that with a mapped kitten or by calling the kitten from the shell.

kovidgoyal commented 6 years ago

kittens are meant to work only with mapping. If you want to create a standalone program that is run with kitty, you can simply create a python script and run it with

kitty +launch /path/to/script.py

that will run just like any python script but you can import kitty packages/modules just as you would in a kitten.

net commented 6 years ago

icat and diff work via kitty kitten <name>. Those aren't mappings, are they?

I was trying to write a kitten because they allow me to forcefully take over the stdin and stdout of a window. I'm not sure just a standalone script will let me do that.

My goal is to, either via a command or a mapping, run rg --files | fzf in the current window for the current directory while another program is running, then do something with the result (either in the kitten, or by somehow writing to the window).

kovidgoyal commented 6 years ago

As I said before, anything you can do in a kitten, you can do in a standalone script run via +launch.

kovidgoyal commented 6 years ago

And if you want to automate things the cirrect place to look is the kitty remote control tool which will allow you to do things like get the cwd and write to windows etc, etc.

net commented 6 years ago

I tried +launch, it doesn't seem to take over stdin/stdout when a program is running, while the same script run as a kitten does.

kovidgoyal commented 6 years ago

I have no idea what you mean by takeover stdin/stdout. kittens work by opening a new window that covers the existing window, they dont take over stdin/stdout. I dont in general see how you can "take over" stdin/stdout. The only way to do that is suspend the running program and then use stdin/stdout just as you would normally.

net commented 6 years ago

Sorry, I was ignorant of the underlying mechanics. The behavior I want is that where the existing window is covered.

kovidgoyal commented 6 years ago

You use a mapping for that. Once the kitten has run, it can insert the resulting text into the underlying window, see the unicode_input kitten for an example.

net commented 6 years ago

I looked at unicode_input, and I have a kitten that somewhat works using window.paste(string)—although I'm not sure if that's the best way to send to the window. My problem is that I need the current working directory and, if possible, other arguments available in the kitten. I was hoping I could start the kitten like icat and diff so that I could pass those arguments in.

kovidgoyal commented 6 years ago

If you want to pass arguments to a kitten you do so in the mapping, like this

map whatever kitten kitten_name arg1 arg2

As for cwd, there is no robust way to get that, since kitty cannot in general know what the cwd of the running process is (think of a process running over ssh). However, for local processes, you can get the cwd using the kitty remote-control tool. See https://sw.kovidgoyal.net/kitty/remote-control.html

kovidgoyal commented 6 years ago

This commit should simplify getting the cwd: https://github.com/kovidgoyal/kitty/commit/9e044750ce8c12c8572f99f5ffd1e1d294a31ee3

the kitten will simply run with cwd set to the cwd of the underlying window.

net commented 6 years ago

Fantastic, thank you!

When I said arguments, I had in mind something like kitty +kitten foo $bar. It's still not clear to me what the difference is between my kittens and icat/diff, but I'll take 9e04475 and run with it 😃.

kovidgoyal commented 6 years ago

icat/diff do not run in their own window, triggered by a map i.e. they are not really kittens but standalone programs that are tied into kittens system for convenience of launching. And where do you expect the value of $bar to come from? Remember that when you launch a kitten via a map, it does not share anything with whatever process is running in the kitty window. Thanks to my last commit it now gets the same cwd (assuming it is a local process) but that's it.

net commented 6 years ago

I see. Thanks.