17 July 2008

xterm select/cut characters

I often use Eterm as my terminal. But, it's a little bit heavy and sometimes I use xterm too. Thing is, xterm is not user friendly and the defaults you get by starting it without options are just horrible.

Now, the basic, cosmetic options for xterm are pretty straight-forward. Also, it's usually good to specify '-ls' to make it a login shell. So:
xterm -ls -bg black -fg yellow -g 120x60

will give you a much nicer looking xterm, and bigger too. Green and cyan also make great foreground colors on the black background.

What really drives me crazy about the default xterm though is the way it selects/cuts text when you double click on something. I often have to do a lot of selecting and pasting and the default just divides on nearly every non-alpha character. There is a solution to that, but it's somewhat involved. I'm going to give you the short story here and tell you how to customize it further. (If you want the long story, try "man xterm".)

This is what I'm using:
xterm -ls -bg black -fg yellow -cc 42:48,45-47:48,126:48 -g 120x60

That takes the characters '*', '-', '.', '/', and '~' and makes them part of character class 48, which already includes all alpha-numeric characters and the underscore character.

Now, if you wanted to add other characters to class 48 so that they'll be included in your double-click selects, you just need to find out the ascii code for those characters and add them to your list. You can find the ascii codes from "man ascii". Use the decimal set.

For example, let's say I wanted to add '=', '?', and '@' to my list of characters to be included in selects. I check the ascii man page and find that their codes are 61, 63, and 64, then I'd add them to the character class list like this:
42:48,45-47:48,61:48,63-64:48,126:48

<ctrl-d>

Labels: ,

01 April 2008

FreeBSD logo screensavers

I've been playing around with xscreensaver (x11/xscreensaver) and I've done something fun with a couple of the hacks that you'll want to try. There are many hacks that let you use your own image or images. Many of those, like XAnalogTV or Carousel, work best with a large number of pictures that get rotated. There are a couple of hacks that only work on one picture at a time, and what I've done is modified some FreeBSD logos to work well with those.

First up is the "blitspin" hack. It chops an image into quarters and then rotates those 90 degrees and then does that again to each quadrant and so on. The effect is of the image being chopped into a blocky fuzz and then reforming, but turned 90 degrees from the last time it was whole. Repeat forever.

To make blitspin look nice with the logo, I needed to find a large logo that fills a large amount of the screen and then I decided to change the background to black. This way it looks like just the (roughly) circular logo is there (instead of the rectangular image). It took some fiddling around, but it looks pretty good now. Oh, and it's blue -- how's that for a twist? (To use this you just need to run xscreensaver-demo and then choose blitspin>Settings>Advanced and add the option "-bitmap /path/to/blueball.png" to the command there.)

The other hack that's just begging for the FreeBSD logo is "flag". Some of the doc.s are outdated and still say that you have to use a bitmap with the hack. That's not true any longer as it turns out. But, it does look a lot better if you use a small image that shows pixelation. So, I'd already made a little bitmap and that's what I'm sticking with. I like this one the best. (To use it, just like before, run xscreensaver-demo and then choose flag>Settings>Advanced and add the option "-bitmap /path/to/Logo_FreeBSD.xbm".)

I'm not sure what the heck happened to the color on flag, though. I've tried a couple of things to get it working with the undulating colors, but no dice. If you can figure that out, let me know! It still looks great though.

The only other thing you need to start using these is the image files themselves. I would like to have just uploaded them to this post, but blogger always modifies and resizes images so that wouldn't work. I searched for free file hosting and went with the first reasonable place that didn't want me to register. So, here are the links: Logo_FreeBSD.xbm blueball.png. (Obviously, these are meant for personal use only, and any sort of commercial use would require permission from the FreeBSD Foundation.)

If you're lucky enough to be able to run FreeBSD on your computer at school or work (yes, I am :) ), then show it off with a logo screensaver!

Labels: , ,

11 December 2007

Stupid printing tricks

Why do so many people send Adobe PDF files? Especially if it's just text. Why not just send text? Why should I have to open another application to read your precious newsletter?!

Ugh. Anyway, sometimes PDF's are useful. Maybe they've got maps and directions or whatever. Then maybe you'll want to print them out. Well, I don't know what's going on with my Adobe Reader (port "print/acroread7"). I know I've printed from it in the past. But, today it's telling me that "/usr/bin/lp" doesn't exist. It bloody well does exist. It doesn't work though, :) , I'm using CUPS and a network printer, so what I want is to use "/usr/local/bin/lp" -- but, sure enough, old acroread is telling me it doesn't exist either. It does.

OK, I'm not going to argue with a broken application. I need a hard copy, fast. So, on to the stupid trick. When you choose "Print" and get that dialog box, down near the bottom is the "Print to file" check box. Check that, choose a filename, click OK, then just pipe the resulting file to "/usr/local/bin/lp" (in my case, anyway) and you're in business. My actual command was something like this: "cat outfile.ps | /usr/local/bin/lp" and Adobe Reader had appended the '.ps' itself. (Not sure if this trick will work with a non-PostScript printer. Might need a little Ghostscript "glue".)

Labels:

10 November 2007

Color your (CLI) world!

Here is a quick tip on adding some color to your command line interface (CLI). And, when I say CLI, I mean both the console and your typical graphical terminal as well (xterm, Eterm, etc.).

First, and easiest, is to color the directory listings. There are two ways to do this. One, you can define the variable CLICOLOR in your environment. In bash, you could do this with the command "export CLICOLOR=1". And, if you really like it, then just put that same statement into your ".bash_profile" file and it will become effective every time you log in. See picture above, and then say either "oooh!" or "aaah!"

The other way to do the exact same thing, is to just add the option "G" to your "ls" commands. Above, I could have gotten the exact same output by typing "ls -ltG" regardless of whether the variable CLICOLOR existed in the environment. I guess if you're already using an alias for "ls" this might be a good way to do it. If you're using several aliases for several different sort of "ls" commands, then maybe CLICOLOR would be better. But, they're both easy to set-up and it doesn't much matter which method you use.

Next, let's get some syntax-sensitive color into our text editor. If you use "vi"* and you do any sort of scripting or programming, you should try installing the port "editors/vim". In fact, I install "editors/vim-lite" because I'm really not interested is using the graphical/X vim. Now, if you open any sort of script file that vim can tell is a script or program**, all you've got to do is enable the syntax setting by typing ":syntax enable" (make this automatic by putting it into your "~/.vimrc" file, colon and all). Once this setting is enabled, vim will color the different words and comments on the screen according to the syntax of the appropriate language -- as long as it has rules settings for that language -- and it has rules already for most. I can tell you it works nicely out of the box for shell and python scripts. If you don't have any scripts or code files handy, see the magic at work on one of the scripts that's already on a FreeBSD box. Maybe try, "vim -R /etc/rc.sendmail". See the screen snip below. Say "aaah!" or "oooh!" as appropriate.


Being an old crank, I've been known to poo-poo this fancy color stuff. By golly, when I was your age we had amber-only WYSE terminals that burned off your eyelashes and warmed all coffee within a 5 foot radius! But, I've got to admit, once you've had a taste of this syntax-sensitive, visual sugar, there's no going back. It really helps you to take in your scripts a lot quicker. And, once you're used to it, you'll howl the next time you have to script or program without it.

*(If you don't use "vi", then I recommend it as a great CLI tool -- and, obviously, its clone "vim", too. Be aware that they're not really, really easy to learn. :) But, they're worth the trouble and can help you to navigate and change files much more quickly than any standard editor.)
**(The way vim normally tells which syntax to use is via the interpreter defined after the shebang on the first line of the script. It might also use file extensions when there is no interpreter defined.)
***(Cool wallpaper behind my transparent Eterm is from Digital Blasphemy.)

Labels: ,

17 October 2007

OpenSearch plugin for Firefox

This is funny. I'm not sure what came first: the chicken or the egg. I'm also not sure which of these came first: me running into this page about creating search plugins for Firefox or my idea to create one for FreshPorts.

Anyway, the idea percolated around for a while. I finally got around to doing it. It was just a little more trouble than I expected, but not too bad. It helped to look at some third-party search plugins that I already had installed. We'll need to find where that directory is anyway. (BTW, this subdirectory won't exist yet if you've never before installed an additional search plugin.) On Unix it's usually something like "$HOME/.mozilla/firefox/*.default/searchplugins/" where "$HOME" is your home directory and "*.default" represents the random looking text along with ".default" that Firefox uses for that directory name. (In Windows, it will be in something like "C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles\*.default\searchplugins\". And on Mac OSX, try "/Users/username/Library/Application Support/Firefox/Profiles/*.default/searchplugins/". (Change "username" to your user name.))

As long as you've installed an add-on search plugin, there should be at least one file in the "searchplugins" directory with a suffix of ".xml". If you look at the contents of that file, you can see a real world example of what we're trying to do for FreshPorts.

So, basically, it's a big game of fill-in-the-blanks. I'll spare you the details of all my starts and stops, and get right to the good stuff. The below is what I ended up with. If you put it into a file named "freshports.xml" in your "searchplugins" directory and then start (or restart) Firefox, you can search FreshPorts straight from the browser's little search box in the navigation tool bar. It even has a nice little daemon picture.

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>FreshPorts</ShortName>
<Description>Everything you want to know about FreeBSD software, ports, packages, and applications.</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAACTElEQVR42oWSTUjTcRjHP/85pw7bnHPOXOkWJlK6LfEk6EqxQ1l4MDp0iMqKqFOX6GDooeiNAqkOlUhERWjZq5WRZlBJk/7FUgvZ1BA1nKhbM910v05Z1lzf2wPf58vneYElNDA4KP6s7zU2C9kpi799ykjN1y9eFZODQwuNPq8Xb/8A7afP4Xr/QeTl26Vf3phIAX73UI1meJgCW0FN/bGTKL+NoA+FiA3OYtAso6HlUW1UAsfWLdSfrSNJr8Fq1HGw+jCJBet491qGZN0iryJSQPWZWqlk7w7G5kMABINz3OxwcfR4HT3PX/4/AGDz9koAvLOzdF5qYPzWDay93Yw2NSM7ZTHh8wsAiSg6su+QeNZ4F7NSRaoQJFgyKK7ahXtyAkfZRrKzzEsTAJy6fEFakWogIATD+iRsVTvpetxKvErDmN/Pj+/jRJXslEWFwSz2pK0SJ9IswpqWKcpSMkVfz+eFf4hKMD46gidG8HVunkmfH7vZQvXta6xek7MwujJagEqtBmBIEWYsTsUBu43i0vWL9haV4E3HKwLT08QqFGQikbXO9o8nIoHslIWrq4vWlqcs15sIh2cIaNX0T00hO2VhNOlITzdLi874qdsl2lo76fV0M/LFjS4lGYC+tx9J8E8Qzs7HXl5KUCiITzHhyDFQ7iiUJI/bI5qamnlx5wHbKitQz4WY0SfTeP8hPb19qLVGALSZVoo2lbDBtpIMo5Fci+k3Qd35K6Kt/QmJQiJLq6OoqJDS/bslj9sjAlM+pLgYctfmRXy6n7Ci4m2PovV/AAAAAElFTkSuQmCC</Image>
<Url type="text/html" method="GET" template="http://www.freshports.org/search.php?query={searchTerms}" />
<Url type="application/x-suggestions+json" template="http://www.freshports.org/faq.php"/>
<moz:SearchForm>http://www.freshports.org/search.php</moz:SearchForm>
</OpenSearchDescription>


(There's going to be some serious line wrapping there. I'm thinking that reading the details of each line right here is less important than having a clean cut-and-paste chunk.)

I'm finding this very useful. I use FreshPorts often to see what's in the latest ports tree, because I don't update my own ports tree every day. (See here if you're curious why.) Going straight to search results saves a lot of time and unneeded page loads.

So, here's the funny part. After I finished all of this, I was so pleased with myself that I just couldn't wait to post it on some mozilla/Firefox site for the rest of the world to enjoy. It seems the right site for that is the Mycroft Project. Well, ... of course, there was a FreshPorts search plugin there already. If you just go to the Mycroft site and type "freshports" in their search box it takes you right to it -- and you can install it with just a couple of clicks. ... Of course, it would make me feel a lot better if you'd cut and paste and use mine. But, I'll understand if you don't.

A small note

The base64 representation of the daemon icon I got out of the "URI Kitchen" (linked from the "Creating OpenSearch Plugins ..." page) was really large. It worked just fine, but was giant. In my version above, therefore, I used the same thing for the image data as the other plugin.

Labels: ,

19 August 2007

Make "Home" and "End" keys work

There was an article linked in the press section of the FreeBSD site that mentioned something pretty cool. It in turn linked to another article with lots of details. More details than suit me frankly. :p But, darned useful nonetheless.

If you have to switch back and forth between W1ndows and Unix often, as do I, you may sometimes reach for a key that doesn't work as you expect it to (or at all). Sometimes when I'm in a hurry I start typing vi commands while writing an email in Outlo0k. It doesn't work. (Too bad, because when you're editing in a hurry, vi commands are what you want!) Well, getting vi or vim to plug in as the editor for Outlo0k will have to wait for another day. :) But, there are some keys that have been non-functional for me on the Unix command line. Now, I've got them back.

Like I said, the above-linked article by Anne Baretta has a ton of details. She talks about settings to enable some of these keys in X, tcsh, KDE, and more. I just scanned down to the part on bash and found what I needed. Namely, you can get the "Home", "End", and "Delete" keys working as expected on the command line in bash by creating a file named ".inputrc" in your home directory that contains the following:

"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[3~": delete-char


As far as I can tell, you'll have to log in again to make it effective.

Wait, there's more! The article mentioned the "Ctrl-v" trick: You hit Ctrl-v and then another key or key combination and then it will show you the escape sequence that gets sent to the shell. Using that trick I discovered that the escapes for "Ctrl-LeftArrow" and "Ctrl-RightArrow" (yeah, more W1ndows lapses) and then mapped those to the appropriate bash readline commands. Just add these two lines more to "~/.inputrc" and you'll be in business with the word hopping arrows:

"\eOD": backward-word
"\eOC": forward-word


I'm in switch-hitters heaven. Furthermore, none of these bindings override the ones that were already there. That is, "Ctrl-A" still goes to the beginning of the line too, and "Alt-F" still hops the cursor forward a word, etc.

Update: Commenter Eddie led me to an interesting article at 'nixCraft' on the same subject. Playing around, I found some interesting things. First, the codes above don't work correctly in all situations!! I was doing that through ssh/PuTty. On a regular terminal, these are the codes that worked right for me:

"\e[7~": beginning-of-line #home
"\e[8~": end-of-line #end
"\e[3~": delete-char #delete
"\eOd": backward-word #ctl-leftarrow
"\eOc": forward-word #ctl-rightarrow


Secondly, if you're on a machine with multiple (command-line) users, then it makes little sense for everyone to have to create the same "~/.inputrc" file. You need only create one file with those readline settings in it, I suggest "/usr/local/etc/inputrc", and then point everyone to it by putting this line into "/etc/profile":

export INPUTRC='/usr/local/etc/inputrc'

Labels: ,

24 February 2007

Enabling your mouse scroll wheel in X

This is a quick tip. It's been around for a while and I'm not even sure where I first saw it. But, if you have a mouse with a roller wheel, you can add this one line option to your X configuration file to enable it. You'll then be able to use it to scroll up and down in your web browser, terminal windows, pretty much any program that has an "up" and "down."

I'm using xorg on my systems now, but I believe the scroll-wheel option was exactly the same in XFree86. In the block for you mouse, which typically looks like this:
Section "InputDevice"
Identifier "Mouse1"
Driver "mouse"
Option "Device" "/dev/sysmouse"
... just add one more line like this:
Option "ZAxisMapping" "4 5"
... restart X and you should be in business.


Whenever the subject is mice, I like to "give the devil his due" and admit that I use
M!cros0ft mice almost exclusively. That's one thing they've always done right. Software, not so much. :) But, a good, plain, optical mouse with a scroll wheel is hard to beat.

Labels: ,