Wednesday Jul 30, 2008

vi style key binding for bash.
Bash supports both emap and vi style key binding. emacs is a default
keybinding. Users need to use "set -o vi" to switch to vi style
binding. I have the carpel tunnel type of problem so I always use vi
style binding. In bash, I want to have multi-key binding e.g "th" bind
to history command, t1 to last command's 1st argument etc. Frankly
speaking, I didn't like the bash vi binding syntax. It is very cryptic
and possibly very error prone. Here are my bindings :

te : Print this help
tl : listing files in current directory(run ls command)
th : show history of last 8 commands
t0-t9 : last command arguments 0-9
tt : Last command's all argument
tk : Don't run(kill) the current command but save it in history.
tr : reverse-search-history but conituation must be done by C-r
tc : Equivalent to ctrl-c. kill line and go to input mode
tw : next word
tq : history with shortcut macro
ts : print history to execute command
ty : Change editor : For internal use only
tx : Execute perl expression on current statement
z : vi-search-again
g : goto mark

How it works :
$ <Esc>te
The above will print the help.
$ ls .bash_keybinding.sh
$ vi <Esc>t1
will expand to
$ vi .bash_keybinding.sh

How dtrace have no impact on performance when probes are not in use.
dtrace probes can be used in any "C" applications. Slowly lots of server
softwares on solaris are integrating dtrace probes in to their core
functionality. Initial fear to a new user is that it may have a impact on
performance. Dtrace replaces probes with "nop" instructions when not in use.
When users typically uses these probes then it have some impact on performance.
I wrote a simple test application to see what happens during runtime of a
process. (testapp.c)

Notice that function "func" doesn't have any instruction. It has two nop
instructions. Let us run the application and run a dtrace program from other
terminal which uses this probe and see what happens to the application during
runtime.

Notice that 1 of the nop is now replaced with trap instruction "ta %icc,". So
when probes are used "nop" instruction is replaced with a trap instruction.
When probes are not in use, it is simply a nop instruction. This is the reason
that probes have no runtime impact on performance of applications when they are
not in use.