# path (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/path.ts](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts).

## Functions

### `basename`

Function.

The last segment of a path (`/` or \`\` separated); trailing separators are ignored.

```ts
function basename(path: string): string
```

**Parameters**

- `path` (`string`): A file or folder path.

**Returns** `string`

Source: [ui/src/path.ts:14](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L14)

### `compactPath`

Function.

Truncate a filesystem path for display so the most useful segments
(the last few) stay readable while the start collapses to an ellipsis.

/Users/yaelguilloux/Code/agent/zidane → /…/agent/zidane

Deliberately NOT core's `compactPath` (`zidane/chat/pure`): core's rule is
`~`-substitution against `$HOME`, which a browser cannot read. Middle-segment
collapse keeps the meaningful tail intact in a narrow sidebar. Falls back
to a hard right-tail truncation when even the last segment overflows.

```ts
function compactPath(path: string, maxChars?: number): string
```

**Parameters**

- `path` (`string`): The path to shorten.
- `maxChars?` (`number`, default `38`): The longest result (default 38).

**Returns** `string`

Source: [ui/src/path.ts:47](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L47)

### `formatPathForCwd`

Function.

A project path as seen from `cwd`. A behavioral fork of core's
`zidane/chat/path-display.ts`: a file above the cwd shows as an absolute
path anchored at the project root, never a `../`-prefixed relative, and
nothing here imports `node:path`.

- An absolute `projectRelativePath` passes through unchanged.
- A file at or below `cwd` → a POSIX relative path (no `./` prefix); `cwd` itself → `.`.
- A file above `cwd` or in a sibling tree → the absolute path.

```ts
function formatPathForCwd(
  projectRelativePath: string,
  projectRoot: string,
  cwd: string,
): string
```

**Parameters**

- `projectRelativePath` (`string`): The path, relative to `projectRoot` (or absolute).
- `projectRoot` (`string`): The project's root folder.
- `cwd` (`string`): The folder the path is shown from.

**Returns** `string`

Source: [ui/src/path.ts:86](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L86)

### `splitPath`

Function.

`a/b/c.ts` → `{ dir: 'a/b', base: 'c.ts' }`; `dir` is '' at the top level. For `/`-separated workspace paths.

```ts
function splitPath(path: string): { base: string; dir: string }
```

**Parameters**

- `path` (`string`): A `/`-separated path.

**Returns** `{ base: string; dir: string }`

Source: [ui/src/path.ts:28](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L28)

### `tildePath`

Function.

`path` with a leading `home` folder shown as `~`: `/Users/ada/code/app` →
`~/code/app`, `/Users/ada` → `~`. Anything else (another user's folder,
`/Users/adam`, a relative path) comes back unchanged. For display only:
never pass the result to anything that reads the disk.

```ts
function tildePath(path: string, home: string | null | undefined): string
```

**Parameters**

- `path` (`string`): The path.
- `home` (`string | null | undefined`): The home folder of the machine the path is on. Absent or empty: `path` unchanged.

**Returns** `string`

Source: [ui/src/path.ts:178](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L178)

### `tildeText`

Function.

`text` with each path in it under `home` shown as `~` (`in /Users/ada/x` →
`in ~/x`): only where the home folder starts a path (the line's start,
after a space, a quote or a bracket) and ends at a path boundary. For
display only.

```ts
function tildeText(text: string, home: string | null | undefined): string
```

**Parameters**

- `text` (`string`): A line that may hold paths.
- `home` (`string | null | undefined`): The home folder of the machine the paths are on. Absent or empty: `text` unchanged.

**Returns** `string`

Source: [ui/src/path.ts:194](https://github.com/Tahul/zidane/blob/main/ui/src/path.ts#L194)
