Skip to content

Instantly share code, notes, and snippets.

View julienr's full-sized avatar

Julien Rebetez julienr

View GitHub Profile
@julienr
julienr / bashrc_prompt_shortener
Created April 19, 2011 21:15
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))