mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Start work on choose files kitten
This commit is contained in:
0
kittens/choose_files/__init__.py
Normal file
0
kittens/choose_files/__init__.py
Normal file
58
kittens/choose_files/main.go
Normal file
58
kittens/choose_files/main.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package choose_files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/kovidgoyal/kitty/tools/cli"
|
||||||
|
"github.com/kovidgoyal/kitty/tools/tty"
|
||||||
|
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = fmt.Print
|
||||||
|
var debugprintln = tty.DebugPrintln
|
||||||
|
|
||||||
|
type Handler struct {
|
||||||
|
lp *loop.Loop
|
||||||
|
Current_base_dir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) OnInitialize() (ans string, err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
|
||||||
|
cwd := ""
|
||||||
|
switch len(args) {
|
||||||
|
case 0:
|
||||||
|
os.Getwd()
|
||||||
|
if cwd, err = os.Getwd(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
cwd = args[0]
|
||||||
|
default:
|
||||||
|
return 1, fmt.Errorf("Can only specify one directory to search in")
|
||||||
|
}
|
||||||
|
lp, err := loop.New()
|
||||||
|
if err != nil {
|
||||||
|
return 1, err
|
||||||
|
}
|
||||||
|
handler := Handler{Current_base_dir: cwd, lp: lp}
|
||||||
|
lp.OnInitialize = handler.OnInitialize
|
||||||
|
err = lp.Run()
|
||||||
|
if err != nil {
|
||||||
|
return 1, err
|
||||||
|
}
|
||||||
|
ds := lp.DeathSignalName()
|
||||||
|
if ds != "" {
|
||||||
|
fmt.Println("Killed by signal: ", ds)
|
||||||
|
lp.KillIfSignalled()
|
||||||
|
return 1, nil
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func EntryPoint(parent *cli.Command) {
|
||||||
|
create_cmd(parent, main)
|
||||||
|
}
|
||||||
32
kittens/choose_files/main.py
Normal file
32
kittens/choose_files/main.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from kitty.simple_cli_definitions import CompletionSpec
|
||||||
|
|
||||||
|
|
||||||
|
def main(args: list[str]) -> None:
|
||||||
|
raise SystemExit('This must be run as kitten choose-files')
|
||||||
|
|
||||||
|
|
||||||
|
usage = '[directory to start choosing files in]'
|
||||||
|
|
||||||
|
|
||||||
|
OPTIONS = '''
|
||||||
|
'''.format
|
||||||
|
|
||||||
|
|
||||||
|
help_text = '''\
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
||||||
|
elif __name__ == '__doc__':
|
||||||
|
cd = sys.cli_docs # type: ignore
|
||||||
|
cd['usage'] = usage
|
||||||
|
cd['options'] = OPTIONS
|
||||||
|
cd['help_text'] = help_text
|
||||||
|
cd['short_desc'] = 'Choose files, fast'
|
||||||
|
cd['args_completion'] = CompletionSpec.from_string('type:directory')
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/kovidgoyal/kitty/kittens/ask"
|
"github.com/kovidgoyal/kitty/kittens/ask"
|
||||||
|
"github.com/kovidgoyal/kitty/kittens/choose_files"
|
||||||
"github.com/kovidgoyal/kitty/kittens/choose_fonts"
|
"github.com/kovidgoyal/kitty/kittens/choose_fonts"
|
||||||
"github.com/kovidgoyal/kitty/kittens/clipboard"
|
"github.com/kovidgoyal/kitty/kittens/clipboard"
|
||||||
"github.com/kovidgoyal/kitty/kittens/desktop_ui"
|
"github.com/kovidgoyal/kitty/kittens/desktop_ui"
|
||||||
@@ -94,6 +95,8 @@ func KittyToolEntryPoints(root *cli.Command) {
|
|||||||
show_error.EntryPoint(root)
|
show_error.EntryPoint(root)
|
||||||
// choose-fonts
|
// choose-fonts
|
||||||
choose_fonts.EntryPoint(root)
|
choose_fonts.EntryPoint(root)
|
||||||
|
// choose-files
|
||||||
|
choose_files.EntryPoint(root)
|
||||||
// query-terminal
|
// query-terminal
|
||||||
query_terminal.EntryPoint(root)
|
query_terminal.EntryPoint(root)
|
||||||
// __pytest__
|
// __pytest__
|
||||||
|
|||||||
Reference in New Issue
Block a user