Skip to content

Instantly share code, notes, and snippets.

@julienr
Created April 19, 2011 21:15
Show Gist options
  • Save julienr/929685 to your computer and use it in GitHub Desktop.
Save julienr/929685 to your computer and use it in GitHub Desktop.
bashrc prompt pwd shortener
# prompt shortener : http://stackoverflow.com/questions/3497885/code-challenge-bash-prompt-path-shortener
_dir_chomp () {
local IFS=/ c=1 n d
local p=(${1/#$HOME/\~}) r=${p[*]}
local s=${#r}
while ((s>$2&&c<${#p[*]}-1))
do
d=${p[c]}
n=1;[[ $d = .* ]]&&n=2
((s-=${#d}-n))
p[c++]=${d:0:n}
done
echo "${p[*]}"
}
PS1='\[\033[01;34m\]$(_dir_chomp "$(pwd)" 20)\[\033[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment