Programming

Display Colored Output in Shell Scripts

Submitted by jbreland on Fri, 06/18/2010 - 04:10

Most modern terminals* (xterm, Linux desktop environment terminals, Linux console, etc.) support ANSI escape sequences for providing colorized output. While I'm not a fan of flash for flash's sake, a little splash of color here and there in the right places can greatly enhance script output.

In Bash, I include the following functions in any script where I want colored output:

# Display colorized information output
function cinfo() {
	COLOR='\033[01;33m'	# bold yellow
	RESET='\033[00;00m'	# normal white
	MESSAGE=${@:-"${RESET}Error: No message passed"}
	echo -e "${COLOR}${MESSAGE}${RESET}"
}
 
# Display colorized warning output
function cwarn() {
	COLOR='\033[01;31m'	# bold red
	RESET='\033[00;00m'	# normal white
	MESSAGE=${@:-"${RESET}Error: No message passed"}
	echo -e "${COLOR}${MESSAGE}${RESET}"
}

This allows me to easily output yellow (cinfo) or red (cwarn) text with a single line in a script. Eg.:

cwarn "Error: operation failed"

If this message was output normally with echo and it was surrounded by a lot of other text, it might be overlooked by the user. By making it red, however, it's significantly more likely to stand out from any surrounding, "normal" output.

My most common use for these functions are simple status output messages. Eg., if I have a script or function that's going to do five different things and display output for each of those tasks, I'd like to have any easy way to visually distinguish each of the steps, as well as easily determine which step the script is on. So, I'll do something like this (from one of my system maintenance scripts):

# Rebuild packages with broken dependencies
cinfo "\nChecking for broken reverse dependencies\n"
revdep-rebuild -i -- -av
# Rebuild packages with new use flags
cinfo "\nChecking for updated ebuild with new USE flags\n"
emerge -DNav world

For more details, the Advanced Bash Scripting guide provides a detailed discussion on using ANSI escape sequences in scripts, both for color and other purposes. You can also find some additional info in the Bash Prompt HOWTO, as well as useful color charts on the Wikipedia page.

*Note: Traditional (read: old) Unixes generally don't support useful modern conveniences like this. If you regularly work with AIX or Solaris and the like, you may want to skip this tip.

Convert to FLAC Updated (again)

Submitted by jbreland on Thu, 05/14/2009 - 22:46

I just pushed out an important bugfix release for Convert to FLAC. When testing the new multiple input file support, I apparently never bothered testing it on files with spaces in their names. Oops. Version 2.0.1 fixes this oversight.

Relevant links below. If you've already upgraded to v2.0, please download this new version ASAP. Sorry for the inconvenience.

For more information:
Convert to FLAC home page and downloads
Convert to FLAC ChangeLog

Feedback and Support

Project/Website Status

Submitted by jbreland on Wed, 11/21/2007 - 06:05

I haven't made very many posts lately, so I just wanted to update everyone that may be wondering what's going on. I've been insanely busy with work, both with my day and side jobs, and I just haven't had much time to work on personal projects. I definitely have some stuff in the works, just finding the time to move forward on any it is really hard to do lately.

I released a beta version of Universal Extractor v1.6 a while back now. That's pretty much ready for release right now, and has been for a couple weeks. I just need to polish a few last things related to the installer and language files, update the website with all of the appropriate new information for the release, and then put it out there. I'm hoping to dedicate some time to finishing this up soon.

I've actually begun working on a new version of AutoFLAC as well, but so far changes have mostly been limited to bug fixes and efficiency/workflow updates. I have some ideas for some pretty useful new features (aside from all of the issues that have been discussed in the Hydrogenaudio AutoFLAC thread), but it'll take a while to implement everything and put out a new release. In the meantime, just rest assured that this project has definitely not been abandoned, despite the fact that it's been over a year since the last release.

Less obvious to most visitors are the various website updates I've slowly been working on. Most of this involves restoring administrative functionality that was lost in my migration from PostNuke to Drupal a few months back (for a good example of this, see my last last post), or introducing some "private" features of the website, such as a new webmail system, that's restricted to specific users. I've also been (slowly) working on various other updates and under-the-hood tweaks to the site and server to keep things running as smoothly as possible.

So, yes, I'm still around, and this website (and associated projects) is still under development. Also, even if I'm busy and things are moving slowly, I'll try to at least update my website more than once a month. :-)

Universal Extract v1.6 beta Available

Submitted by jbreland on Thu, 08/09/2007 - 08:44

I made available a beta version of the upcoming v1.6 release of Universal Extractor last night. I'm not making it available through the UniExtract home page because it's only a beta; it needs a lot of testing before official release. However, if you're interested in testing some of the new features and providing feedback on your results, you can find find change details and download links in this MSFN UniExtract forum post.

Inno Setup Support Scripts Update

Submitted by jbreland on Wed, 08/08/2007 - 01:06

I just posted updates to my Inno Setup CLI Help and Modify Path Inno Setup scripts. The CLI Help is a fairly small update - it just includes updated documentation for the latest version of Inno Setup.

The ModPath update is a bit more substantial; I added the ability to add multiple directories to the system path instead of just a single directory. Usually this capability should not be necessary, but I had a need to do this for the new version of Universal Extractor that's currently in development. If you're currently using an older version of the script, though, be sure to read the updated directions. This new version is not directly compatible with older versions and requires a few small changes to your main installer script.

The updates can be downloaded from each script's home page:
Inno Setup CLI Help
Modify Path

Google Code Search

Submitted by jbreland on Thu, 10/05/2006 - 14:00

Google recently introduced a new search service specifically for source code. Google Code Search "helps you find function definitions and sample code by giving you one place to search publicly accessible source code hosted on the Internet." I played with it very briefly, and it definitely seems to have potential. A FAQ is also provided to help you get started.

CRN published an article covering Google Code Search. It's worth a quick read if you ever have a need for this sort of thing (which, admittedly, most folks do not).

Full links:
Google Code Search - http://google.com/codesearch
CRN article - http://www.crn.com/sections/breakingnews/breakingnews.jhtml?articleId=193104796

Rapid Application Development with QT

Submitted by jbreland on Thu, 11/13/2003 - 22:14

There's a pretty short but to-the-point tutorial on using Qt Designer to create quick and easy GUI apps over on DevChannel (part of IBM's wonderful developerWorks network). This tutorial is primarily intended to give you a quick overview on how to create a very basic application, but it gives you a good introduction to the development environment as a whole, and well worth a look if you've ever considered developing with Qt.

Here's the tutorial