Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shell): add case insensitivity to filecontent method #4306

26 changes: 22 additions & 4 deletions src/platform/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,32 @@ func (env *Shell) FileContent(file string) string {
if !filepath.IsAbs(file) {
file = filepath.Join(env.Pwd(), file)
}
content, err := os.ReadFile(file)

// Get all files in the directory of the file
globOfFilesInDir := filepath.Join(filepath.Dir(file), "*")
matches, err := filepath.Glob(globOfFilesInDir)
if err != nil {
env.Error(err)
return ""
}
fileContent := string(content)
env.Debug(fileContent)
return fileContent

// For each file found in the directory of the file we want to read its contents
for _, match := range matches {
// Do a case insensitive comparison of the file name to find the file we want
if strings.EqualFold(filepath.Base(match), filepath.Base(file)) {
content, err := os.ReadFile(match)
if err != nil {
env.Error(err)
return ""
}
fileContent := string(content)
env.Debug(fileContent)
return fileContent
}
}

env.Debug("File not found")
return ""
}

func (env *Shell) LsDir(path string) []fs.DirEntry {
Expand Down