Friday, October 22, 2010

Show short path on shell prompt

If your configuration file have

PS1='$NAME@$PWD'

and the path is deep, the line is almost covered by path name. You can just show the deepest folder by

PS1='$NAME@$(PWD##*/)'

If you need last three folder name, you need some complicated code like the following:

function ncd {
cd "$*"
PS1=$(echo $NAME@$PWD|awk -F'/' '{printf("%s/",$1);for(i=2;i< NF ; i++) {if(i",$i);}')
}
alias cd=ncd

No comments:

Post a Comment