on main help sign in
refactor: rename `internal/fileutil` into `internal/fsutil`
commit8033779ea6704a758d2939478a5bf02103d9b7a2 authorAndrey Nering <andreynering@users.noreply.github.com> dateMon 16 Jun 2025, 17:21 (1 year ago) parent93b41c9
9 files changed+27−27
internal/fileutil/fileutil.go → internal/fsext/fileutil.go+1−1 internal/fileutil/ls.go → internal/fsext/ls.go+1−1 internal/llm/tools/glob.go+4−4 internal/llm/tools/grep.go+2−2 internal/llm/tools/ls.go+2−2 internal/tui/components/chat/editor/editor.go+2−2 internal/tui/components/chat/messages/renderer.go+7−7 internal/tui/components/chat/sidebar/sidebar.go+2−2 internal/tui/components/dialogs/permissions/permissions.go+6−6
internal/fileutil/fileutil.go → internal/fsext/fileutil.gorenamed+1−1
@@ -1,4 +1,4 @@
1−package fileutil
1+package fsext
22
33import (
44 "fmt"
internal/fileutil/ls.go → internal/fsext/ls.gorenamed+1−1
@@ -1,4 +1,4 @@
1−package fileutil
1+package fsext
22
33import (
44 "os"
internal/llm/tools/glob.go+4−4
@@ -11,7 +11,7 @@ import (
1111 "strings"
1212
1313 "github.com/charmbracelet/crush/internal/config"
14− "github.com/charmbracelet/crush/internal/fileutil"
14+ "github.com/charmbracelet/crush/internal/fsext"
1515 "github.com/charmbracelet/crush/internal/logging"
1616)
1717
@@ -127,7 +127,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
127127}
128128
129129func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
130− cmdRg := fileutil.GetRgCmd(pattern)
130+ cmdRg := fsext.GetRgCmd(pattern)
131131 if cmdRg != nil {
132132 cmdRg.Dir = searchPath
133133 matches, err := runRipgrep(cmdRg, searchPath, limit)
@@ -137,7 +137,7 @@ func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
137137 logging.Warn(fmt.Sprintf("Ripgrep execution failed: %v. Falling back to doublestar.", err))
138138 }
139139
140− return fileutil.GlobWithDoubleStar(pattern, searchPath, limit)
140+ return fsext.GlobWithDoubleStar(pattern, searchPath, limit)
141141}
142142
143143func runRipgrep(cmd *exec.Cmd, searchRoot string, limit int) ([]string, error) {
@@ -158,7 +158,7 @@ func runRipgrep(cmd *exec.Cmd, searchRoot string, limit int) ([]string, error) {
158158 if !filepath.IsAbs(absPath) {
159159 absPath = filepath.Join(searchRoot, absPath)
160160 }
161− if fileutil.SkipHidden(absPath) {
161+ if fsext.SkipHidden(absPath) {
162162 continue
163163 }
164164 matches = append(matches, absPath)
internal/llm/tools/grep.go+2−2
@@ -17,7 +17,7 @@ import (
1717 "time"
1818
1919 "github.com/charmbracelet/crush/internal/config"
20− "github.com/charmbracelet/crush/internal/fileutil"
20+ "github.com/charmbracelet/crush/internal/fsext"
2121)
2222
2323// regexCache provides thread-safe caching of compiled regex patterns
@@ -342,7 +342,7 @@ func searchFilesWithRegex(pattern, rootPath, include string) ([]grepMatch, error
342342 return nil // Skip directories
343343 }
344344
345− if fileutil.SkipHidden(path) {
345+ if fsext.SkipHidden(path) {
346346 return nil
347347 }
348348
internal/llm/tools/ls.go+2−2
@@ -9,7 +9,7 @@ import (
99 "strings"
1010
1111 "github.com/charmbracelet/crush/internal/config"
12− "github.com/charmbracelet/crush/internal/fileutil"
12+ "github.com/charmbracelet/crush/internal/fsext"
1313)
1414
1515type LSParams struct {
@@ -108,7 +108,7 @@ func (l *lsTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) {
108108 return NewTextErrorResponse(fmt.Sprintf("path does not exist: %s", searchPath)), nil
109109 }
110110
111− files, truncated, err := fileutil.ListDirectory(searchPath, params.Ignore, MaxLSFiles)
111+ files, truncated, err := fsext.ListDirectory(searchPath, params.Ignore, MaxLSFiles)
112112 if err != nil {
113113 return ToolResponse{}, fmt.Errorf("error listing directory: %w", err)
114114 }
internal/tui/components/chat/editor/editor.go+2−2
@@ -12,7 +12,7 @@ import (
1212 "github.com/charmbracelet/bubbles/v2/textarea"
1313 tea "github.com/charmbracelet/bubbletea/v2"
1414 "github.com/charmbracelet/crush/internal/app"
15− "github.com/charmbracelet/crush/internal/fileutil"
15+ "github.com/charmbracelet/crush/internal/fsext"
1616 "github.com/charmbracelet/crush/internal/logging"
1717 "github.com/charmbracelet/crush/internal/message"
1818 "github.com/charmbracelet/crush/internal/session"
@@ -327,7 +327,7 @@ func (m *editorCmp) SetPosition(x, y int) tea.Cmd {
327327}
328328
329329func (m *editorCmp) startCompletions() tea.Msg {
330− files, _, _ := fileutil.ListDirectory(".", []string{}, 0)
330+ files, _, _ := fsext.ListDirectory(".", []string{}, 0)
331331 completionItems := make([]completions.Completion, 0, len(files))
332332 for _, file := range files {
333333 file = strings.TrimPrefix(file, "./")
internal/tui/components/chat/messages/renderer.go+7−7
@@ -6,7 +6,7 @@ import (
66 "strings"
77 "time"
88
9− "github.com/charmbracelet/crush/internal/fileutil"
9+ "github.com/charmbracelet/crush/internal/fsext"
1010 "github.com/charmbracelet/crush/internal/highlight"
1111 "github.com/charmbracelet/crush/internal/llm/agent"
1212 "github.com/charmbracelet/crush/internal/llm/tools"
@@ -208,7 +208,7 @@ func (vr viewRenderer) Render(v *toolCallCmp) string {
208208 return vr.renderError(v, "Invalid view parameters")
209209 }
210210
211− file := fileutil.PrettyPath(params.FilePath)
211+ file := fsext.PrettyPath(params.FilePath)
212212 args := newParamBuilder().
213213 addMain(file).
214214 addKeyValue("limit", formatNonZero(params.Limit)).
@@ -248,7 +248,7 @@ func (er editRenderer) Render(v *toolCallCmp) string {
248248 return er.renderError(v, "Invalid edit parameters")
249249 }
250250
251− file := fileutil.PrettyPath(params.FilePath)
251+ file := fsext.PrettyPath(params.FilePath)
252252 args := newParamBuilder().addMain(file).build()
253253
254254 return er.renderWithParams(v, "Edit", args, func() string {
@@ -258,8 +258,8 @@ func (er editRenderer) Render(v *toolCallCmp) string {
258258 }
259259
260260 formatter := core.DiffFormatter().
261− Before(fileutil.PrettyPath(params.FilePath), meta.OldContent).
262− After(fileutil.PrettyPath(params.FilePath), meta.NewContent).
261+ Before(fsext.PrettyPath(params.FilePath), meta.OldContent).
262+ After(fsext.PrettyPath(params.FilePath), meta.NewContent).
263263 Split().
264264 Width(v.textWidth() - 2) // -2 for padding
265265 return formatter.String()
@@ -282,7 +282,7 @@ func (wr writeRenderer) Render(v *toolCallCmp) string {
282282 return wr.renderError(v, "Invalid write parameters")
283283 }
284284
285− file := fileutil.PrettyPath(params.FilePath)
285+ file := fsext.PrettyPath(params.FilePath)
286286 args := newParamBuilder().addMain(file).build()
287287
288288 return wr.renderWithParams(v, "Write", args, func() string {
@@ -412,7 +412,7 @@ func (lr lsRenderer) Render(v *toolCallCmp) string {
412412 if path == "" {
413413 path = "."
414414 }
415− path = fileutil.PrettyPath(path)
415+ path = fsext.PrettyPath(path)
416416
417417 args := newParamBuilder().addMain(path).build()
418418
internal/tui/components/chat/sidebar/sidebar.go+2−2
@@ -9,7 +9,7 @@ import (
99 tea "github.com/charmbracelet/bubbletea/v2"
1010 "github.com/charmbracelet/crush/internal/config"
1111 "github.com/charmbracelet/crush/internal/diff"
12− "github.com/charmbracelet/crush/internal/fileutil"
12+ "github.com/charmbracelet/crush/internal/fsext"
1313 "github.com/charmbracelet/crush/internal/history"
1414 "github.com/charmbracelet/crush/internal/llm/models"
1515 "github.com/charmbracelet/crush/internal/logging"
@@ -231,7 +231,7 @@ func (m *sidebarCmp) filesBlock() string {
231231 }
232232
233233 extraContent := strings.Join(statusParts, " ")
234− filePath := fileutil.DirTrim(fileutil.PrettyPath(file.FilePath), 2)
234+ filePath := fsext.DirTrim(fsext.PrettyPath(file.FilePath), 2)
235235 filePath = ansi.Truncate(filePath, maxWidth-lipgloss.Width(extraContent)-2, "…")
236236 fileList = append(fileList,
237237 core.Status(
internal/tui/components/dialogs/permissions/permissions.go+6−6
@@ -8,7 +8,7 @@ import (
88 "github.com/charmbracelet/bubbles/v2/viewport"
99 tea "github.com/charmbracelet/bubbletea/v2"
1010 "github.com/charmbracelet/crush/internal/diff"
11− "github.com/charmbracelet/crush/internal/fileutil"
11+ "github.com/charmbracelet/crush/internal/fsext"
1212 "github.com/charmbracelet/crush/internal/llm/tools"
1313 "github.com/charmbracelet/crush/internal/permission"
1414 "github.com/charmbracelet/crush/internal/tui/components/core"
@@ -170,7 +170,7 @@ func (p *permissionDialogCmp) renderHeader() string {
170170 pathKey := t.S().Muted.Render("Path")
171171 pathValue := t.S().Text.
172172 Width(p.width - lipgloss.Width(pathKey)).
173− Render(fmt.Sprintf(" %s", fileutil.PrettyPath(p.permission.Path)))
173+ Render(fmt.Sprintf(" %s", fsext.PrettyPath(p.permission.Path)))
174174
175175 headerParts := []string{
176176 lipgloss.JoinHorizontal(
@@ -196,7 +196,7 @@ func (p *permissionDialogCmp) renderHeader() string {
196196 fileKey := t.S().Muted.Render("File")
197197 filePath := t.S().Text.
198198 Width(p.width - lipgloss.Width(fileKey)).
199− Render(fmt.Sprintf(" %s", fileutil.PrettyPath(params.FilePath)))
199+ Render(fmt.Sprintf(" %s", fsext.PrettyPath(params.FilePath)))
200200 headerParts = append(headerParts,
201201 lipgloss.JoinHorizontal(
202202 lipgloss.Left,
@@ -211,7 +211,7 @@ func (p *permissionDialogCmp) renderHeader() string {
211211 fileKey := t.S().Muted.Render("File")
212212 filePath := t.S().Text.
213213 Width(p.width - lipgloss.Width(fileKey)).
214− Render(fmt.Sprintf(" %s", fileutil.PrettyPath(params.FilePath)))
214+ Render(fmt.Sprintf(" %s", fsext.PrettyPath(params.FilePath)))
215215 headerParts = append(headerParts,
216216 lipgloss.JoinHorizontal(
217217 lipgloss.Left,
@@ -268,8 +268,8 @@ func (p *permissionDialogCmp) renderBashContent() string {
268268func (p *permissionDialogCmp) renderEditContent() string {
269269 if pr, ok := p.permission.Params.(tools.EditPermissionsParams); ok {
270270 formatter := core.DiffFormatter().
271− Before(fileutil.PrettyPath(pr.FilePath), pr.OldContent).
272− After(fileutil.PrettyPath(pr.FilePath), pr.NewContent).
271+ Before(fsext.PrettyPath(pr.FilePath), pr.OldContent).
272+ After(fsext.PrettyPath(pr.FilePath), pr.NewContent).
273273 Width(p.contentViewPort.Width()).
274274 Split()
275275