//View Tip #155
Similar Tips
» swap files
» Tar remote dir over SSH
» Create a Terminal Calculator
» Insert last argument
» Simple password generator

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
The script below will truncate the $PWD to 1/4 of the terminal width and put it into the command prompt, all within the same bash process, no forks to tr and gawk.

function truncate_pwd

{
newPWD="${PWD/#$HOME/~}"
local pwdmaxlen=$((${COLUMNS:-80}/4))
if [ ${#newPWD} -gt $pwdmaxlen ]
then
newPWD=".+${newPWD: -$pwdmaxlen}"
fi
}

PROMPT_COMMAND=truncate_pwd
PS1="${ttyname}@\h:\${newPWD}\\$ "



View Comments »




Comments 

Add your comment

Comments are currently disabled
No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit