Now that Cygwin is just a keyboard shortcut away, it’s time to explore a little of what it can do.
Download files: wget
This is a tool built into Cygwin that makes it easy to download files without needing a web browser. Simply type wget [a url] to download a single file.
But wget has a lot more features than that. For example, if you want to download a lot of files, you can save a list of URLs to a text file, putting each URL on its own line. Then, open cygwin and type wget -i listoffiles.txt and wget will download each file, one after another.
If you’re looking for more interesting ways to use wget, you’ll probably find this Lifehacker post relevant.
Get weather forecasts: weather
When we’re finished, you will be able to type the word weather into the console and get back a list of current local weather conditions and a local weather forecast (example). We’ll be using a shell script written by Jeremy Stanley to make this happen.
NOTE: Since this script pulls its forecast information from the U.S. National Weather Service, forecasts are only available for US territories. However, international readers can still get their current weather conditions since that data is provided by local airports.
- Download the latest version of the script.
- Open it by typing
tar -xvf [filename]and change to the new folder by typingcd [new folder name]. - optional If you want to try the script out, typing in
./weather ATLwill return the current conditions at the Atlanta airport. - Now, to get your local conditions/forecast, you’ll need to edit the
weatherrcfile in your favorite text editor. Add the following lines to the top of the file (after the copyright notice).
[default]
Forecast = True
City = Greenville Spartanburg
St = SC
ID = KGSPThat’s the configuration to get my local forecast. To get yours, we’ll need to change the city, st, and ID variables to your location.
To get a forecast, you’ll need to put in a city that the National Weather Service provides information for. Go here and select your state to find what cities are available. If you don’t want a forecast, just delete the
Forecast = Trueline.To get current conditions, you’ll need to provide the METAR id for your nearest airport. Go to this map and click on the city closest to you. Under the map will be the METAR id for that airport.
Save the weatherrc file and type
./weatherinto cygwin. It should give you a local forecast with current weather conditions. - optional Let’s make it so that you can get your weather from anywhere in the file system and so that you don’t have to type that annoying
./beforehand. We’re gonna have to move some files around.If it doesn’t already exist in your home folder, make a folder called bin (
mkdir bin). Move just theweatherfile to that folder. Make sure it’s executable by typingchmod +x weather.Next, type
python -c "import sys ; print sys.path"to find out where to putweather.pyandweather.pyc. I put mine in/usr/lib/python2.5Then, move
weather.1andweatherrc.5to/usr/share/local/man/man1, which is where cygwin stores manual files. (Once you do this, you can typeman weatherorman weatherrcto find out more about how to use this weather script.)Finally, move
weatherrcto your home folder. I recommend renaming it.weatherrc, which will make it invisible to thelscommand.Now, you’ll need to make sure cygwin knows to look in the bin folder for the weather script. Open the
.bash_profilefile in your home folder and make sure these lines are included and not commented out:if [ -d "${HOME}/bin" ] ; then
PATH=${HOME}/bin:${PATH}
fiOnce you’ve done all that, type
weatherinto cygwin, and it should give you the forecast and current conditions no matter where you are in the file system.
Manage a todo list: todo
Gina Tripani from Lifehacker has started an open source command line todo list manager. Once installed you can type things like todo add "Write blog post" to add an item to your todo list, todo ls to get a list of things to do, and todo do 1 to cross off the first thing on the list, and a lot more.
You can find plenty more about the script and how to install it at the link above.
Update twitter: tweet
This python script will let you easily send messages to Twitter from the command line. Simply copy and paste this code to a text file and save it as tweet.py (ideally in the bin directory you made above). To make it even more convenient, comment out or delete these lines:
user = raw_input(‘Username: ‘)
password = raw_input(‘Password: ‘)
and replace them with:
user = “your twitter user name”
password = “your twitter password”
Then open the .bash_profile file again and add this line to the bottom of the file:
alias tweet=’tweet.py’
Now you can type tweet "Message to send to twitter" to send tweets from the command line.
Solve math problems: solve
This one is easy: simply add the following lines to the end of your .bash_profile file:
function solve () {
awk “BEGIN { print $* ; }”
}
Now you can type solve "2*(3+4)" and it will return 14.
Hope you all find some of these tools useful! If you have any that you want to share, feel free to leave a comment.