Skip to content

Reduce path components to one letter, like vim buffer names.

Notifications You must be signed in to change notification settings

tupton/compact-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compact Path

CircleCI Build Status

Reduce path elements to one character save the last element, like vim buffer names.

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.

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.

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.

~/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 and how I use it in my prompt.

About

Reduce path components to one letter, like vim buffer names.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages