MCPcopy Create free account
hub / github.com/52funny/pikpakcli / completeLocalPath

Function completeLocalPath

internal/shell/shell.go:392–435  ·  view source on GitHub ↗
(prefix string, onlyDirs bool)

Source from the content-addressed store, hash-verified

390}
391
392func completeLocalPath(prefix string, onlyDirs bool) ([][]rune, int) {
393 expandedPrefix := utils.ExpandLocalPath(prefix)
394 parentPath := "."
395 basePrefix := prefix
396 namePrefix := expandedPrefix
397 hasTrailingSeparator := strings.HasSuffix(prefix, string(filepath.Separator))
398
399 if strings.TrimSpace(prefix) == "" {
400 basePrefix = ""
401 namePrefix = ""
402 } else if !hasTrailingSeparator {
403 parentPath = filepath.Dir(expandedPrefix)
404 if parentPath == "." && filepath.IsAbs(expandedPrefix) {
405 parentPath = string(filepath.Separator)
406 }
407 namePrefix = filepath.Base(expandedPrefix)
408 } else {
409 parentPath = expandedPrefix
410 namePrefix = ""
411 }
412
413 entries, err := os.ReadDir(parentPath)
414 if err != nil {
415 return nil, len([]rune(basePrefix))
416 }
417
418 candidates := make([]string, 0)
419 for _, entry := range entries {
420 if onlyDirs && !entry.IsDir() {
421 continue
422 }
423 if !strings.HasPrefix(entry.Name(), namePrefix) {
424 continue
425 }
426
427 remaining := entry.Name()[len(namePrefix):]
428 if entry.IsDir() {
429 remaining += string(filepath.Separator)
430 }
431 candidates = append(candidates, escapeShellCompletion(remaining))
432 }
433
434 return toRuneCandidates(candidates), len([]rune(basePrefix))
435}
436
437func promptForPath(currentPath string) string {
438 if currentPath == "/" {

Callers 1

DoMethod · 0.85

Calls 3

ExpandLocalPathFunction · 0.92
escapeShellCompletionFunction · 0.85
toRuneCandidatesFunction · 0.85

Tested by

no test coverage detected