mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
parent
ccefeb05ff
commit
17f2d2c574
2 changed files with 13 additions and 21 deletions
|
|
@ -912,8 +912,6 @@ class EditCmd:
|
|||
self.file_data = b''
|
||||
self.file_inode = -1, -1
|
||||
self.file_size = -1
|
||||
self.file_spec = ''
|
||||
self.line_number = 0
|
||||
self.version = 0
|
||||
self.source_window_id = self.editor_window_id = -1
|
||||
self.abort_signaled = ''
|
||||
|
|
@ -936,7 +934,15 @@ class EditCmd:
|
|||
return
|
||||
if self.version > 0:
|
||||
raise ValueError(f'Unsupported version received in edit protocol: {self.version}')
|
||||
self.opts, _ = parse_opts_for_clone(['--type=overlay'] + self.args)
|
||||
self.opts, extra_args = parse_opts_for_clone(['--type=overlay'] + self.args)
|
||||
self.file_spec = extra_args.pop()
|
||||
self.line_number = 0
|
||||
import re
|
||||
pat = re.compile(r'\+(-?\d+)')
|
||||
for x in extra_args:
|
||||
m = pat.match(x)
|
||||
if m is not None:
|
||||
self.line_number = int(m.group(1))
|
||||
self.file_name = os.path.basename(self.file_spec)
|
||||
self.file_localpath = os.path.normpath(os.path.join(self.cwd, self.file_spec))
|
||||
self.is_local_file = False
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ func edit_loop(data_to_send string, kill_if_signaled bool, on_data OnDataCallbac
|
|||
return
|
||||
}
|
||||
|
||||
func edit_in_kitty(path string, opts *Options, line_number int) (err error) {
|
||||
func edit_in_kitty(path string, opts *Options) (err error) {
|
||||
read_file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to open %s for reading with error: %w", path, err)
|
||||
|
|
@ -206,8 +206,6 @@ func edit_in_kitty(path string, opts *Options, line_number int) (err error) {
|
|||
return fmt.Errorf("Failed to get the current working directory with error: %w", err)
|
||||
}
|
||||
add_encoded("cwd", cwd)
|
||||
add_encoded("file_spec", path)
|
||||
add_encoded("line_number", strconv.Itoa(line_number))
|
||||
for _, arg := range os.Args[2:] {
|
||||
add_encoded("a", arg)
|
||||
}
|
||||
|
|
@ -247,28 +245,16 @@ func EntryPoint(parent *cli.Command) *cli.Command {
|
|||
fmt.Fprintln(os.Stderr, "Usage:", cmd.Usage)
|
||||
return 1, fmt.Errorf("No file to edit specified.")
|
||||
}
|
||||
lineNumber := 0
|
||||
fileArgs := []string{}
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "+") {
|
||||
ln, err := strconv.Atoi(arg[1:])
|
||||
if err == nil {
|
||||
lineNumber = ln
|
||||
continue
|
||||
}
|
||||
}
|
||||
fileArgs = append(fileArgs, arg)
|
||||
}
|
||||
if len(fileArgs) != 1 {
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintln(os.Stderr, "Usage:", cmd.Usage)
|
||||
return 1, fmt.Errorf("Only one file to edit must be specified, optionally with a line number")
|
||||
return 1, fmt.Errorf("Only one file to edit must be specified")
|
||||
}
|
||||
var opts Options
|
||||
err = cmd.GetOptionValues(&opts)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
err = edit_in_kitty(fileArgs[0], &opts, lineNumber)
|
||||
err = edit_in_kitty(args[0], &opts)
|
||||
return 0, err
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue