{"id":16775767,"url":"https://github.com/tupton/compact-path","last_synced_at":"2026-05-22T05:02:24.248Z","repository":{"id":26174849,"uuid":"29620509","full_name":"tupton/compact-path","owner":"tupton","description":"Reduce path components to one letter, like vim buffer names.","archived":false,"fork":false,"pushed_at":"2022-08-25T17:38:20.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T04:44:13.210Z","etag":null,"topics":["python","shell","utility"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tupton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-21T22:06:35.000Z","updated_at":"2022-08-25T16:58:10.000Z","dependencies_parsed_at":"2022-08-21T04:00:20.751Z","dependency_job_id":null,"html_url":"https://github.com/tupton/compact-path","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupton%2Fcompact-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupton%2Fcompact-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupton%2Fcompact-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupton%2Fcompact-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tupton","download_url":"https://codeload.github.com/tupton/compact-path/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910820,"owners_count":20367545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","shell","utility"],"created_at":"2024-10-13T07:07:32.111Z","updated_at":"2026-05-22T05:02:23.791Z","avatar_url":"https://github.com/tupton.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compact Path\n\n[![CircleCI Build Status](https://circleci.com/gh/tupton/compact-path/tree/master.svg?style=svg)](https://circleci.com/gh/tupton/compact-path/tree/master)\n\nReduce path elements to one character save the last element, like vim buffer names.\n\n``` sh\n❯ pwd\n/Users/tupton/code/compact_path\n❯ python compact_path.py $(pwd)\n/U/t/c/compact_path\n❯ python compact_path.py $(pwd | sed \"s:$HOME:~:\")\n~/c/compact_path\n```\n\nPass the `--trigger` or `-t` option to specify the length at which compaction will\ntake place. Any paths that are *less* than this length will not be compacted.\n\n``` sh\n❯ pwd\n/Users/tupton/code/compact_path\n❯ python compact_path.py $(pwd) --trigger 35\n/Users/tupton/code/compact_path\n❯ python compact_path.py $(pwd) -t 10\n/U/t/c/compact_path\n```\n\nYou can use this in your shell prompt.\n\n``` sh\nfunction compact_path() {\n    local cp=\"/usr/local/bin/compact_path\"\n    if [[ -e \"$cp\" ]]; then\n        echo $(\"$cp\" \"$1\" --trigger 20)\n    else\n        echo \"$1\"\n    fi\n}\n\nPROMPT='$(compact_path \"${PWD/#$HOME/~}\") %# '\n```\n\nIn `zsh`, that would result in a prompt that looks like the following.\n\n``` sh\n~/code/compact_path % cd /usr/local/Library/Homebrew/\n/u/l/L/Homebrew % cd ~/code/compact_path\n~/code/compact_path %\n```\n\nSee my `zshrc` for the actual [`compact_path` function][cp] and how I use it [in my prompt][p].\n\n  [cp]: https://github.com/tupton/dotfiles/blob/656350a5a060ec5cf162fe02f6c8f3e3cdebf3d4/zsh/zshrc.d/prompt.zsh#L18-L25\n  [p]: https://github.com/tupton/dotfiles/blob/656350a5a060ec5cf162fe02f6c8f3e3cdebf3d4/zsh/zshrc.d/prompt.zsh#L101\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupton%2Fcompact-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftupton%2Fcompact-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupton%2Fcompact-path/lists"}