completeFilePath autocompleta caminhos de arquivos
(prefix string)
| 493 | |
| 494 | // completeFilePath autocompleta caminhos de arquivos |
| 495 | func (cli *ChatCLI) completeFilePath(prefix string) []string { |
| 496 | var completions []string |
| 497 | |
| 498 | dir, filePrefix := filepath.Split(prefix) |
| 499 | if dir == "" { |
| 500 | dir = "." |
| 501 | } |
| 502 | |
| 503 | // Expandir "~" para o diretório home |
| 504 | dir = os.ExpandEnv(dir) |
| 505 | if strings.HasPrefix(dir, "~") { |
| 506 | homeDir, err := os.UserHomeDir() |
| 507 | if err == nil { |
| 508 | dir = filepath.Join(homeDir, dir[1:]) |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | files, err := os.ReadDir(dir) |
| 513 | if err != nil { |
| 514 | return completions |
| 515 | } |
| 516 | |
| 517 | for _, entry := range files { |
| 518 | name := entry.Name() |
| 519 | if strings.HasPrefix(name, filePrefix) { |
| 520 | path := filepath.Join(dir, name) |
| 521 | if entry.IsDir() { |
| 522 | path += string(os.PathSeparator) |
| 523 | } |
| 524 | completions = append(completions, path) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | return completions |
| 529 | } |
| 530 | |
| 531 | // completeSystemCommands autocompleta comandos do sistema |
| 532 | func (cli *ChatCLI) completeSystemCommands(prefix string) []string { |