Tag Archive "gnome-terminal"

custom command prompt

Published January 22nd, 2010 by Chad

I spend a lot of time in the terminal and at the command prompt. The default prompt for Ubuntu is very…unhelpful, to say the least. I already know who I am and most of the time I know what machine I am on. So after talking to a friend of mine and doing a little research I have come up with this custom command prompt that suits me just fine.

custom command prompt screenshot

custom command prompt screenshot

The first part is the time that the prompt was given. This idea came from my friend. I like it for things like figuring out just how long that last command took (without having to run it again with the time command) and for simply seeing what time it is (since I am in the terminal a lot).

The next part is the current directory I am working in. I made it a different color to make it stand out a bit more from the rest of the stuff on the screen. So, with a quick glance, I can determine if I am in the right place before running the command.

The last part is the coolest (in my opinion) by far. I found an example of the smiley faces being used and really liked that idea. Once again at a glance I can determine something important. This time, I can determine whether or not the last command was successful. If I see red, I can look back and see what happened. If no red, keep going, everything is just fine. Pretty cool.

Now to the nitty gritty. How exactly do you create a custom prompt like this. After ripping things from a few different places (and doing a lot of my own troubleshooting) I came up with this for my custom command prompt: PS1="[\e[00m][\T] [\e[1;34m]\w `if [ \$? = 0 ]; then echo -e '[\e[01;32m]:)'; else echo -e '[\e[01;31m]:('; fi` [\033[00m]\$[\e[00m] "

Confused? :) I was too. In fact, I am still unsure as to what exactly some of it does. Oh well.

The segments that look like [e[00m] (sometimes with different numbers) are specifying the colors of the different sections. The first part you can see that after the color specification section there is a [\T]. This simply specifies that the current time (\T) needs to be printed between some square brackets ([]).

Next there are some more colors specified followed by \w. This specifies that I want the current working directory displayed. A capital W will display the current working directory without the path.

Then comes the fun stuff. Bash scripting within a string! Basically it says that if the last command was all good, display a smiley face. However, if something went wrong, a frowning face is displayed (in red). The bash scripting is just a simple if-else statement with some echo calls.

The key here is making sure everything is escaped correctly. Add a comment if you have any questions. BTW, here is another good reference for this type of thing.

changing gnome-terminal default window size

Published December 8th, 2009 by Chad

I actually like the default window size for the gnome-terminal in Ubuntu now. But I used to not like it. There was a time when I would run a command, see that the output of the command wasn’t displayed nicely, resize the window manually, and rerun the command. Annoying. If you would like to change the default gnome-terminal window size just follow these steps.

  • Open terminal window.
  • Type: sudo gedit /usr/share/vte/termcap/xterm
  • Find the following line: :co#80:it#8:li#24:\
  • Change to your desired window size (the number after :co is the number of columns and the number after :li is for the number of lines): :co#200:it#8:li#50:\
  • Save and close the file.

Every gnome-terminal you open now with use this new window size as the default. This will only work after you have closed all of the opened gnome-terminal windows first. Enjoy.

gnome-terminal transparency issue

Published December 2nd, 2008 by Chad

I have installed the new Ubuntu 8.10 on both my home desktop computer as well as my work laptop. After doing so I turned on the transparency feature of the gnome-terminal (the default terminal app for Ubuntu). On my home computer this feature would work as expected, I could see windows behind the terminal window. However, on my work computer I was seeing the desktop image. Even when there were windows behind the terminal window I saw nothing but the desktop image, not even the desktop icons were displayed.

This was very frustrating to me. I really like some of that visual candy and having it at home, but not at work was a bummer. However it turns out that the solution is simple. All I had to do was enable compiz. I had it installed on both machines, I just didn’t have it enabled on my work computer. NICE!

This is still a little frustrating. I can’t have “truley” transparent terminal windows unless I enable another application that seems to bring with it a little overhead.