From 94e6f240a6eea34ad0bbdefa2373d242ef5f1e9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Jul 2025 14:36:19 +0530 Subject: [PATCH] Allow running python kittens via the kitten binary It just delegates to kitty +kitten automatically --- tools/cmd/main.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/cmd/main.go b/tools/cmd/main.go index 875dec48b..1c8aa0c1c 100644 --- a/tools/cmd/main.go +++ b/tools/cmd/main.go @@ -3,12 +3,17 @@ package main import ( + "fmt" "os" + "path/filepath" + "strings" "github.com/kovidgoyal/kitty/kittens/ssh" "github.com/kovidgoyal/kitty/tools/cli" "github.com/kovidgoyal/kitty/tools/cmd/completion" "github.com/kovidgoyal/kitty/tools/cmd/tool" + "github.com/kovidgoyal/kitty/tools/utils" + "golang.org/x/sys/unix" ) func KittenMain(args ...string) { @@ -24,13 +29,26 @@ func KittenMain(args ...string) { root.HelpText = "kitten serves as a launcher for running individual kittens. Each kitten can be run as :code:`kitten command`. The list of available kittens is given below." root.Usage = "command [command options] [command args]" root.Run = func(cmd *cli.Command, args []string) (int, error) { - cmd.ShowHelp() - return 0, nil + if len(args) == 0 { + cmd.ShowHelp() + return 0, nil + } + if strings.HasSuffix(args[0], ".py") { + exe := utils.KittyExe() + if !filepath.IsAbs(exe) { + exe = utils.Which(exe) + } + if err := unix.Exec(exe, append([]string{filepath.Base(exe), "+kitten"}, args...), os.Environ()); err != nil { + return 1, fmt.Errorf("failed to run python kitten: %s as could not run kitty executable, with error: %w", args[0], err) + } + } + return 1, fmt.Errorf(":yellow:`%s` is not a known kitten. Use --help to get a list of known kittens.", args[0]) } tool.KittyToolEntryPoints(root) completion.EntryPoint(root) + root.SubCommandIsOptional = true root.Exec(args...) }