//View Tip #155
Similar Tips
» Simple password generator
» Manipulate Bash sockets using /dev/tcp
» Check low space
» Randomize lines in a file
» Get latest stable version of the Linux kernel


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

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

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

View Comments »


Add your comment

Comments are currently disabled
No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit