Weather Information in Linux Terminal

2:37 AM

Linux Terminal makes life easy for day to day administration on a Linux Desktop. And if you are a Power user and spend most of the time on the command prompt, you might want to have some dynamic information such as Weather condition available each time you open the Terminal.



Here is a way to get Weather Information in the Linux Terminal both in graphic (gnome, KDE, Unity) and text login (Ctrl + Alt + F1 to F7) modes.

First install the weather-util package from apt repositories.
  • $ sudo apt-get install weather-util
You’ll need your local weather code, which you can get from this website.

For Graphic Login:

Open the .bashrc file
  •  $ sudo vi ~/.bashrc
Press Insert, And append the following lines at the end of the file.

# Weather Information
weather -i CODE 
Where CODE is the code of your location, like VIDP is the code of New Delhi in my case.

Press Esc, and :wq to save and exit the vi editor.

Close the Terminal and reopen, it will display the weather information before the bash prompt.

For Text Login:

You first need to create a script in the appropriate location using vi editor.
  • $  sudo vi /etc/update-motd.d/98-weather
Press Insert and enter the following code, replacing CODE with your local weather code
#!/bin/sh
echo
weather -i CODE
echo
Press Esc, and :wq to save and exit.

Make it executable using chmod
  • sudo chmod +x /etc/update-motd.d/98-weather

Press Ctrl + Alt + F1 and login to see the script working.

Voila :)






0 comments

» read more....

How To Modify Bash Prompt

5:06 PM

Bash Shell is a powerful stuff in Linux. We can do almost everything there. Installing and removing applications, doing system upgrade, downloading files, even listening to your favorite songs. Although, there are many GUI applications which can do such tasks, many people still love using command prompt because it's handy, incredibly fast and we can see exactly happens in the background. If you are one of those people who loves using command prompt to perform such tasks, you might want to read this post on how to modify bash prompt.


What is bash prompt? Bash prompt is a like a bridge connects you to the shell. Bash prompt is a place where you type a command to ask the shell to perform a task. Bash prompt is usually represented by a dollar sign "$".

By default, Ubuntu and its derivative has bash prompt with the following format:
  • hok00age@Laptop-Q:~$
The above bash prompt format can be divided into three parts:
1. The word "hok00age" is username who types the command.
2. The word "Laptop-Q" is the hostname of the computer.
3. The character "~" is the working directory of current shell.

Today, I'd like to show you how to change this bash prompt format into something like this:
  • [08:47:50][hok00age]:~$
The first part of the above format "[08:47:50]" is the current time of the computer.

How to do that? Simply type the following command on currently opened Terminal:
  • export PS1="[\t][\u]:\w\$ "
Please pay attention on the above command. The part who will become "current time" in bash prompt is "\t", "\u" will become username, and you can guess that "\w" will become working directory. The key of this trick is bash prompt special characters to display any information on the shell. You can see all of available special characters that can be used to modify bash prompt here.

Please note, that any modifications you've made only affect the currently active shell. In other words, if you open a new Terminal emulator window, bash prompt is still in Ubuntu default. To make it permanent, you have to edit ".bashrc" file located in home directory. Open it with your favorite text editor or simply type the following command:
  • gedit ~/.bashrc
All you need to do is adding export PS1="[\t][\u]:\w\$ " line to the end of .bashrc file (see the figure below):


Now save the change and test it by opening new Terminal window.

Regards :)

0 comments

» read more....