//View Tip #155
» Find and replace with backup
» Alter autocompletion settings
» Vi mode in bash
» Close shell keeping all subprocess running
Similar Tips
» Insert last argument» Find and replace with backup
» Alter autocompletion settings
» Vi mode in bash
» Close shell keeping all subprocess running
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}\\$ "
Comments
Add your comment
Comments are currently disabled
No Comments

