Saturday, May 24, 2008

Some bash scripts.

Make your console nicer and more useful:
user-) cd Download/
WD=/home/user/Download
user-Download-)
Insert this code to .bashrc file in your home folder:
function SetPS1()
{
local HostBit=""
if test "$OS" = "Linux"
then
if test "`who|grep "$USER"|grep \"tty[1-6]\"`" = ""
then
HostBit="@\h"
fi
fi
local DirBit="-\W"
test "`pwd`" = "$HOME" && DirBit=""
case "$TERM" in
xterm|linux) PS1="\[\]\u\[\]$HostBit\[\]$DirBit\[\]-) " ;;
*) PS1="\u$HostBit$DirBit-) " ;;
esac
}

SetPS1

thcd()
{
builtin cd "$@"
if test -t 1
then
case $TERM in
xterm) echo "WD=`pwd`" >&2
echo -n "]0;XT `basename \"\`pwd\`\"`" >&2 ;;
*) echo "WD=`pwd`" >&2 ;;
esac
fi
SetPS1
}
alias cd='thcd'

No comments: