Linux Tips


Audio Volume in Shell Prompt
Code Folding in Vim
C Prog Debug Location
DMA for DVD and CD in RH8
J-Pilot symlink for USB cradle
Num Lock (.Xmodmap)
Remove Weird Filenames

Audio Volume in Shell Prompt

You can put the current audio volume in your shell prompt with:

export PS1="`aumix -vq | cut -f3 -d' '` $ "

PS1 is the environment variable that bash uses for the command prompt.  The back quotes (``) mean run the enclosed command and substitute the output every time the shell prompts you. The $ is a traditional shell prompt character.

You can do this with other commands besides aumix if you want to display other information in the prompt.

Return to Top

Code Folding in Vim

Vim versions 6.0 and later support a new feature called Code Folding.  With code folding, a block of code can be "folded" into a single line, thus making the overall code easier to grasp.

The Vim commands to use code folding are quite simple:

To create a fold, position the cursor at the start of the code block and type zfap.

To open a fold, type zo.

To close a fold, type zc.

To open all the folds, type zr.

To close all the folds, type zm.

For more commands and information on code folding in Vim, query Vim's built-in help feature, :help folding. Also, make sure you are in command mode when using this commands. If you are in text-entry mode, typing "zfap" embeds the string in your text.

Return to Top

C Prog Debug Location

Tech Tip

Use the __LINE__, __FUNCTION__, and __FILE__ macros to identify where you are in a C program. This could be handy for all those "debugging printf()s".

printf("Welcome to line %d, "
"in the function %s, "
"in the file %s.\n",
__LINE__, __FUNCTION__, __FILE__);

Return to Top

DMA for DVD and CD in RH8

In their wisdom, the people at redhat decided to turn off DMA for CD and DVD devices in an even "more reliable" way than before.  To be able to turn on DMA _at_all_ you have to add the following line in /etc/modules.conf:

options ide-cd dma=1

Reboot.

Return to Top

J-Pilot symlink for USB cradle

/dev/pilot -> /dev/usb/ttyUSB1

Return to Top

Num Lock (.Xmodmap)

When you boot Linux, the kernel turns off Num Lock by default. This isn't a problem if, for you, the numeric keypad is the no-man's-land between the cursor keys and the mouse. But if you're an accountant, or setting up a system for an accountant, you probably don't want to turn it on every single time.

Here's the easy way, if you're using KDE. Go to K --> Preferences --> Peripherals --> Keyboard and select the Advanced tab. Select the radio button of your choice under NumLock on KDE startup and click OK.

If you only run KDE and want Num Lock on when you start a KDE session, you're done. Otherwise, read on.

To set Num Lock on in a virtual console, use:

setleds +num

If you choose to put this in a .bashrc file to set Num Lock when you log in, make it:

setleds +num &> /dev/null

to suppress the error message you'll get if you try it in an xterm or over an SSH connection.

Finally, here's the way to hit this problem with a big hammer--make the numeric keypad always work as a numeric keypad in X, no matter what Num Lock says. This will make them never work as cursor keys, but  you're fine with that because you have cursor keys, right? Create a file called .Xmodmap in your home directory, and insert these lines:

keycode 79=7
keycode 80=8
keycode 81=9

keycode 83=4
keycode 84=5
keycode 85=6

keycode 86=plus
keycode 87=1
keycode 88=2
keycode 89=3

keycode 90=0
keycode 91=period

keycode 77=Escape

(from a Usenet post by Yvan Loranger:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3BFD087F.2000300%40iquebec.com&rnum=3+)

The last line takes the now-useless Num Lock key and makes it an extra Escape key. If your favorite accounting software uses one of the F keys frequently, you might prefer that.

The number to the left of the equals sign is an X "keycode", the key on the keyboard you pressed, and the number or name to the right is an X "keysym", the character or function X thinks it is. You don't have to look these up in some X manual. To find out the keycode and keysym for any key, run xev in an xterm, move the mouse to the small white xev window and watch the keycodes and keysyms scroll by in the xterm.

Return to Top

Remove Weird Filenames

If you want to remove a file called -rf, simply type rm -- -rf. The -- tells rm that everything after -- is a filename, not an option.

Return to Top