Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tupton/compact-path
Reduce path components to one letter, like vim buffer names.
https://github.com/tupton/compact-path
python shell utility
Last synced: 6 days ago
JSON representation
Reduce path components to one letter, like vim buffer names.
- Host: GitHub
- URL: https://github.com/tupton/compact-path
- Owner: tupton
- Created: 2015-01-21T22:06:35.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-08-25T17:38:20.000Z (over 2 years ago)
- Last Synced: 2024-11-22T17:51:43.618Z (2 months ago)
- Topics: python, shell, utility
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Compact Path
[![CircleCI Build Status](https://circleci.com/gh/tupton/compact-path/tree/master.svg?style=svg)](https://circleci.com/gh/tupton/compact-path/tree/master)
Reduce path elements to one character save the last element, like vim buffer names.
``` sh
❯ pwd
/Users/tupton/code/compact_path
❯ python compact_path.py $(pwd)
/U/t/c/compact_path
❯ python compact_path.py $(pwd | sed "s:$HOME:~:")
~/c/compact_path
```Pass the `--trigger` or `-t` option to specify the length at which compaction will
take place. Any paths that are *less* than this length will not be compacted.``` sh
❯ pwd
/Users/tupton/code/compact_path
❯ python compact_path.py $(pwd) --trigger 35
/Users/tupton/code/compact_path
❯ python compact_path.py $(pwd) -t 10
/U/t/c/compact_path
```You can use this in your shell prompt.
``` sh
function compact_path() {
local cp="/usr/local/bin/compact_path"
if [[ -e "$cp" ]]; then
echo $("$cp" "$1" --trigger 20)
else
echo "$1"
fi
}PROMPT='$(compact_path "${PWD/#$HOME/~}") %# '
```In `zsh`, that would result in a prompt that looks like the following.
``` sh
~/code/compact_path % cd /usr/local/Library/Homebrew/
/u/l/L/Homebrew % cd ~/code/compact_path
~/code/compact_path %
```See my `zshrc` for the actual [`compact_path` function][cp] and how I use it [in my prompt][p].
[cp]: https://github.com/tupton/dotfiles/blob/656350a5a060ec5cf162fe02f6c8f3e3cdebf3d4/zsh/zshrc.d/prompt.zsh#L18-L25
[p]: https://github.com/tupton/dotfiles/blob/656350a5a060ec5cf162fe02f6c8f3e3cdebf3d4/zsh/zshrc.d/prompt.zsh#L101