Friday, June 26, 2009

History and page up/down keys in Fedora

In Fedora, the page-up and page-down keys are mapped to beginning of history and end of history which I don't find very useful. These entries are in "/etc/inputrc".

"\e[5~": beginning-of-history
"\e[6~": end-of-history

I prefer to have them mapped to search history forwards and backwards. It allows me to type the beginning of the command and hit page up/down and bash will auto complete the command by recalling the command from history. Here is relevant parts of "/etc/inputrc" which achieves this effect.

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Thursday, June 25, 2009

Enable bash-completion in Fedora

Here are the steps to enable bash-completion in Fedora.
Fedora does not install bash-completion by default. So, first install it.

$ sudo yum install bash-completion

Put the following lines in your ".bashrc" file.

#Bash completion
[ -f /etc/bash_completion ] && source /etc/bash_completion

Turning off annoying beeping in gvim

In order to turn off the annoying beeping in gvim put the following in your ".gvimrc".

" Turn off the annoying beeping and flashing
set visualbell t_vb=

This enables the "visualbell" which flashes instead of beeping.The "t_vb=" turns of the flashing also.

Wednesday, June 24, 2009

Exclude/blacklist a mirror from yum

I have installed the fastestmirror plugin for yum. The mirror that yum finds using this plugin is sometimes unavailable. Fastestmirror plugin allows you exclude/blacklist one or more mirrors.

Add the following line to "/etc/yum/pluginconf.d"

exclude=mirror.example.com

Sunday, June 21, 2009

Splitting a file name into name and extension using bash

I was writing a bash script and wanted to split a file name into its constituent name and extension parts. Here is how I did it.

#!/bin/bash

INPUT_FILE=$1
FILE_NAME=${INPUT_FILE%.*}
FILE_EXT=${INPUT_FILE##*.}

echo $FILE_NAME
echo $FILE_EXT

A good reference for bash script is Advanced Bash Scripting Guide. I referred to the string manipulation section to create the above snippet.

Configuring network profiles in Gentoo

I use my laptop at home and at work. At home, network is configured as static IP address and at work it is using DHCP. So, I needed solution to switch between the two easily. Here is what I came up with.
The contents of my "/etc/conf.d/net" is shown below.

modules_eth0=( "dhclient" )

config_work=( "dhcp" )

config_home="192.168.1.254 netmask 255.255.255.0 brd 192.168.0.255"
routes_home="default via 192.168.1.1"
dns_servers_home="127.0.0.1 192.168.1.1"

cmdline_opt() {
if [ $# -ne 1 ] || ! [ -r /proc/cmdline ]; then
return 1
fi

for opt in $(cat /proc/cmdline) ; do
[ "${opt}" = "${1}" ] && return 0
done

return 1
}

preup() {
if [ "${IFACE}" = "eth0" ] ; then
if cmdline_opt location=home ; then
einfo "Setting network profile: home"
_configure_variables "home"
elif cmdline_opt location=work ; then
einfo "Setting network profile: work"
_configure_variables "work"
else
return 1
fi
fi

# Remember to return 0 on success
return 0
}

I pass "location" as kernel parameter when I boot the machine. So, I added it to the kernel boot line in "grub.conf". I choose the appropriate kernel to boot from the grub menu depending on whether I am at home or work. The relevant portions of my "grub.conf" is shown below.

title Gentoo Vanilla Sources (2.6.28-ab1) (Home)
root (hd0,4)
kernel /boot/kernel-genkernel-x86-2.6.28-ab1 ro real_root=/dev/sda5 location=home

title Gentoo Vanilla Sources (2.6.28-ab1) (Work)
root (hd0,4)
kernel /boot/kernel-genkernel-x86-2.6.28-ab1 ro real_root=/dev/sda5 location=work


If there are any easier/cleaner solutions I would like to hear about them.

Syntax Highlighting in Blogger

I am using Alex Gorbatchev's excellent Syntax Highlighter scripts.

To enable syntax highlighting in your blog posts, add the following code snippet in the HTML head section of your template.

<link href='http://alexgorbatchev.com/pub/sh/2.0.320/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/2.0.320/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shCore.js"></script>
<script language='javascript' src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shLegacy.js'/>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushBash.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDelphi.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDiff.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushGroovy.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPhp.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPlain.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPython.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushRuby.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPerl.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushScala.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushVb.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushAS3.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJavaFX.js"></script>
<script language='javascript' src="http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPowerShell.js"></script>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = "http://alexgorbatchev.com/pub/sh/2.0.320/scripts/clipboard.swf";
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

To illustrate the use of SyntaxHighlighter, lets use a simple "helloworld" C program. You can enclose code snippets in your posting using the <pre> tag as shown below.

<pre class="brush: c">
#include <stdio.h>

int main() {
printf("Hello World!\n");
exit(0);
}
</pre>

If you want to post Python code instead, change the "brush" to "python" as shown below.

<pre class="brush: python">
#!/usr/bin/env python
print "Hello World"
</pre>

You can find the full list of supported languages ("brushes") here.

If you have a place to host the SyntaxHighlighter files then you can test and push out new versions when they become available. Also, if you want to modify the code this is an easier option. That is what I have done. So, my template configuration looks as shown below.

<link href='http://arunbhanu.com/sh/Styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://arunbhanu.com/sh/Styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script language='javascript' src='http://arunbhanu.com/sh/Scripts/shCore.js'></script>
.
.
.

Saturday, June 20, 2009

Setting Git Author and Email

To set git author and email fields globally use the following commands:
 
$ git config --global user.name 'Foo Bar'
$ git config --global user.email 'foo@bar.com'

These commands will add the entries to "user" section of "${HOME}/.gitconfig".

Gentoo "net.example"

On a Gentoo Linux system, a simple help file with examples on how to configure the network settings were previously located in "/etc/conf.d/". I was trying to find this file today and was unable to locate it.

Now, you can find the same file under "/usr/share/doc/openrc/net.example" instead.

Friday, June 19, 2009

Locking KDE session

In KDE 3.5 and KDE 4.2, Ctrl+Alt+l (ie. small letter L) shortcut key is the default mapping for locking your KDE session.

Monday, June 1, 2009

Recursive dos2unix

To recursively convert a directory containing files with DOS newlines to UNIX newlines use the following command:

$ find . -type f -exec dos2unix {} \;