Skip to content

Refactor: shortPath/cwd label function has a third copy in Sidebar.tsx (extends #36) #60

Description

@KrisPowers

Summary

Issue #36 tracks the duplicate `cwd` display label function in `App.tsx` and `Terminal.tsx`. There is a third copy in `app/frontend/src/components/Sidebar.tsx` (lines 11-15):

```ts
function shortPath(p: string): string {
const parts = p.replace(//g, '/').split('/').filter(Boolean)
if (parts.length === 0) return '~'
return parts.length <= 2 ? parts.join('/') : parts.slice(-2).join('/')
}
```

This version also has a subtle difference from the `App.tsx` version: it does not strip a trailing slash before splitting, so a path ending in `/` can produce an empty final segment. All three implementations should be replaced by the single canonical `shortCwd()` function proposed in #36.

Files

  • `app/frontend/src/components/Sidebar.tsx` (lines 11-15, `shortPath`)
  • `app/frontend/src/App.tsx` (lines 84-89, `tabNameFromCwd`)
  • `app/frontend/src/components/Terminal.tsx` (lines 857-861, `cwdLabel` useMemo)
  • New file: `app/frontend/src/lib/pathUtils.ts` (canonical `shortCwd` export)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions