https://github.com/xavdid/truncated-directory
A small utility for printing your location in the filesystem, but truncating large repo subpaths
https://github.com/xavdid/truncated-directory
cli rust shell-prompt starship-prompt zsh
Last synced: about 1 month ago
JSON representation
A small utility for printing your location in the filesystem, but truncating large repo subpaths
- Host: GitHub
- URL: https://github.com/xavdid/truncated-directory
- Owner: xavdid
- Created: 2024-06-07T07:35:02.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-02T05:44:55.000Z (10 months ago)
- Last Synced: 2025-10-11T02:22:50.533Z (8 months ago)
- Topics: cli, rust, shell-prompt, starship-prompt, zsh
- Language: Rust
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# truncated-directory
This is a little Rust CLI use to display the path in my [starship](https://starship.rs/) shell prompt on macOS and Linux. It's based on [this issue](https://github.com/starship/starship/issues/4199).
## Installation
It's not available in a package manager, so just clone and compile it on your own. You can point starship it, wherever it lives. See [how I do it](https://github.com/xavdid/dotfiles/blob/ba7b811467cf2d27659670e326a85470981e616b/config/starship.toml#L60-L66) if you want an example of usage.
To compile, run `just build` (after installing [just](https://github.com/casey/just)). By default it'll dump the binary into `~/bin` but you can also pass a different directory (e.g. `just build some/directory`).
## Examples
Here's how each of the following directories is displayed:
```
/ <-- /
└── Users/ <-- /Users
└── xavdid/ <-- 🏠 ~
├── projects/ <-- ~/projects
│ └── some-repo/ <-- some-repo
│ └── a/ <-- some-repo/a
│ └── b/ <-- some-repo/a/b
│ └── c/ <-- some-repo/…/b/c
└── Desktop/ <-- ~/Desktop
└── d/ <-- ~/Desktop/d
└── e/ <-- Desktop/d/e
└── f/ <-- d/e/f
```
## Logic
It prints the current directory based on the following logic:
- if not under a git repo:
- the current directory and (at most) the two above it.
- replaces home with `~` when visible
- if under a git repo:
- always show the directory of the repo root
- show at most 2 directories under that
- if you're more than two directories down from the repo root, truncate everything between