Total Pageviews

Tuesday, July 9, 2013

Remove lengthly word from command promtp

There are many kind of script out there,but this is what suite me best. The script limit a command prompt to 30 character, if longer than that its will show only the first 12 and last 15 characters. The "\h" in the last line is added to show a hostname, convenient if you often work on remote machine.

To use, just put the following text in ./bashrc file. 

#--- Custom terminal, cutout lengthly word ---
PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
PS1='[\h:$CurDir] \$ '

No comments:

Post a Comment