| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Monday, October 19, 2009

Slick BASH Prompt

UPDATED! 30 October 2009 - I found out how to stop the annoying line wrapping bugs where input wouldn't wrap properly and would over-write part of the prompt if you deleted the input. The code below has been updated.

I had seen some really awesome BASH prompts a few months ago and decided it was time to buckle down and "pimp my prompt". I have to say that I'm VERY happy with how it turned out!
The horizontal line between the directory and the 24hr clock on the right edge of the screen will dynamically resize depending on the width of the terminal. If you'd like to incorporate this into your BASH prompt, it's as easy as this:

  1. gedit ~/.bashrc

  2. comment out the lines that start with "PS1="
    from

    PS1=blahblahblah

    to

    #PS1=blahblahblah

  3. Copy/paste the code below into your .bashrc
    hostn=$(hostname -s)
    usern=$(whoami)

    #black="\e[0;30m"
    #lgreen="\e[32;1m"
    #white="\e[1;37m"
    #lgray="\e[1;30m"
    #lgray="\e[1;32m"
    #dgray="\e[1;30m"
    #uwhite="\e[4;37;1m"
    #uwhite="\e[37m"
    #ublack="\e[4;30m"

    userc="\[\e[1;30m\]"
    timec="\[\e[1;30m\]"
    typec="\[\e[1;30m\]"
    dirc="\[\e[1;30m\]"
    nc="\[\e[0m\]"

    function prompt {

    ctime=$(date +%R)
    prmpt="-[${usern}@${hostn}][${PWD}][${ctime}]"
    cols=$(tput cols)
    let FILLS=${cols}-${#prmpt}
    LINE=""

    if [[ "$PWD" =~ "/home/$usern" ]]
    then
    let FILLS=$FILLS+5+${#usern}
    fi

    for (( f=0; f<$FILLS; f++ )) do LINE=$LINE"\e(0q\e(B" done PS1="$nc\[\e(0l\e(B\]<$userc\u$nc@$userc\h$nc><$dirc\w$nc>${LINE}<$timec${ctime}$nc>\n"
    PS1=$PS1"\[\e(0\]m\[\e(B\]<$typec\$$nc>\[\e(0\]q\[\e(B\]<" } PROMPT_COMMAND=prompt


TIP: If you hack this up, try to put as much of the code OUTSIDE the function {} as possible to reduce the time it takes your terminal to render the prompt.

Thursday, October 15, 2009

Manually Activate Ubuntu Screensaver

Yikes, has it really been two weeks since my last post?! Real life can really sneak up on you and suck up all your blogging time.

Anyway, to break the silence, I thought I'd share this handy little tweak that I came up with earlier today. As you may know, I have a EeePC 701 that's running Ubuntu 9.04. Now the 701 only has a 7" screen so my pixels are at a premium and I don't want to just throw them around willy-nilly. Thankfully, Compiz helps me save that screen real estate very effectively.

Now for the good stuff:
gnome-screensaver-command -a
This command will activate your screensaver manually, no waiting for the inactivity timer to kick in. Compiz Configuration Manager lets you bind commands to key combinations, mouse clicks, and ... Edge Bindings!

Personally, I find Edge Bindings to be awesome. Some folks don't, but I sure do. Edge Bindings basically trigger some kind of action when your mouse touches a certain edge of the screen. Here's how to activate your screensaver when you move the mouse to, say, the bottom-left corner of the screen:
  1. Open "Compiz Configuration Manager"
  2. Open the "Commands" window (it was the first icon in the "General" section in CCM)
  3. In the "Commands" tab, type the following into "Command line 0":
    gnome-screensaver-command -a
  4. On the "Edge Bindings" tab, click on the "Run command 0" button and pick the part(s) of the screen that you want to trigger your screensaver.
  5. And don't forget to activate the "Commands" checkbox from the CCM main screen by checking the checkbox next to it.