Skip to content

Commit 94e6f24

Browse files
committed
Allow running python kittens via the kitten binary
It just delegates to kitty +kitten automatically
1 parent 7205b2a commit 94e6f24

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tools/cmd/main.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
package main
44

55
import (
6+
"fmt"
67
"os"
8+
"path/filepath"
9+
"strings"
710

811
"github.com/kovidgoyal/kitty/kittens/ssh"
912
"github.com/kovidgoyal/kitty/tools/cli"
1013
"github.com/kovidgoyal/kitty/tools/cmd/completion"
1114
"github.com/kovidgoyal/kitty/tools/cmd/tool"
15+
"github.com/kovidgoyal/kitty/tools/utils"
16+
"golang.org/x/sys/unix"
1217
)
1318

1419
func KittenMain(args ...string) {
@@ -24,13 +29,26 @@ func KittenMain(args ...string) {
2429
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."
2530
root.Usage = "command [command options] [command args]"
2631
root.Run = func(cmd *cli.Command, args []string) (int, error) {
27-
cmd.ShowHelp()
28-
return 0, nil
32+
if len(args) == 0 {
33+
cmd.ShowHelp()
34+
return 0, nil
35+
}
36+
if strings.HasSuffix(args[0], ".py") {
37+
exe := utils.KittyExe()
38+
if !filepath.IsAbs(exe) {
39+
exe = utils.Which(exe)
40+
}
41+
if err := unix.Exec(exe, append([]string{filepath.Base(exe), "+kitten"}, args...), os.Environ()); err != nil {
42+
return 1, fmt.Errorf("failed to run python kitten: %s as could not run kitty executable, with error: %w", args[0], err)
43+
}
44+
}
45+
return 1, fmt.Errorf(":yellow:`%s` is not a known kitten. Use --help to get a list of known kittens.", args[0])
2946
}
3047

3148
tool.KittyToolEntryPoints(root)
3249
completion.EntryPoint(root)
3350

51+
root.SubCommandIsOptional = true
3452
root.Exec(args...)
3553
}
3654

0 commit comments

Comments
 (0)