~bin/
things in my bin
Tue Mar 9 16:54:39 2010

Successive versions of Ubuntu have moved farther and farther from using xorg.conf to do stuff. In Karmic, to get (vertical and horizontal) scrolling with middleclick+mouse on my x61t, I had to write a magic hal policy file:

OLD AND BUSTED:

In /etc/hal/fdi/policy/10-mouse.fdi (or something):

<match key="info.product" string="TPPS/2 IBM TrackPoint">
 <merge key="input.x11_options.EmulateWheel" type="string">true</merge>
 <merge key="input.x11_options.EmulateWheelButton" type="string">2</merge>
 <merge key="input.x11_options.YAxisMapping" type="string">4 5</merge>
 <merge key="input.x11_options.XAxisMapping" type="string">6 7</merge>
 <merge key="input.x11_options.Emulate3Buttons" type="string">false</merge>
 <merge key="input.x11_options.EmulateWheelTimeout" type="string">200</merge>
</match>

In Lucid, hal is old and busted, and udev is the new hotness. hal is gone, so of course scrolling broke. It took a while to find the udev way:

NEW HOTNESS:

In /etc/udev/rules.d/99-local-xorg.rules (or something):

ACTION!="add|change", GOTO="xorg_local_end"
KERNEL!="event*", GOTO="xorg_local_end"

ENV{ID_INPUT_MOUSE}!="1", GOTO="xorg_local_end"
ATTRS{idProduct}!="TPPS/2 IBM TrackPoint", GOTO="xorg_local_end"

ENV{x11_options.EmulateWheel}="true"
ENV{x11_options.EmulateWheelButton}="2"
ENV{x11_options.YAxisMapping}="4 5"
ENV{x11_options.XAxisMapping}="6 7"
ENV{x11_options.Emulate3Buttons}="false"
ENV{x11_options.EmulateWheelTimeout}="200"

LABEL="xorg_local_end"

It was hard to find a lot of useful information on udev rules, these urls helped, especially the kubuntu link:

https://wiki.ubuntu.com/X/Config/Input
http://daniel.hahler.de/hal-configuration-fdi-for-kingsis-peripherals-evoluent-verticalmouse-3
https://wiki.kubuntu.org/X/InputConfiguration

The tool you use to get some sort of idea what udev stuff is udevadm. I dunno a lot about it, but here's some of the kind of stuff you do with it ...

UDEVADM EXAMPLES:

udevadm info --query=all --attribute-walk --name="/dev/input/event7
udevadm info --query=all --attribute-walk --name="/dev/input/by-path/platform-i8042-serio-1-event-mouse
udevadm info --query=all --path="/devices/platform/i8042/serio1/input/input7"
udevadm info --query=all --attribute-walk --path=/sys/class/input/mouse1
Fri Jan 29 08:34:04 2010

Tinkering around with something today, cause I end up in directories like:

/client/company1/archive/in/837

wanting to go to

/client/company2/archive/in/837

I wrote it a few ways - so far I think I like this the best. So yeah, with this function in my .bashrc I can say

s company1 company2

to sed pwd and do that directory hop.

# cd with sed
# example:
# /usr/lib/foo$ s lib src
# /usr/src/foo$
s() {
 local cd="$PWD"
 if [ "$1" = "--complete" ]; then
  awk -v q="${2/s /}" -v p="$PWD" '
   BEGIN {
    split(p,a,"/")
    for( i in a ) if( a[i] && tolower(a[i]) ~ tolower(q) ) print a[i]
   }
  '
 else
  while [ $1 ]; do
   cd="$(echo $cd | sed "s/$1/$2/")"
   shift; shift
  done
  shopt -s cdspell
  cd $cd
  shopt -u cdspell
 fi
}
complete -C 's --complete "$COMP_LINE"' s

It takes pairs of arguments and seds arg to arg+1. The shopt stuff fixes some typos - I dunno why I don't like it enabled all the time - but I feel like it has a bit more panache than just a [ -d "$cd" ] && cd $cd.

(Updated to add tab completion)

Fri Dec 4 10:17:37 2009

Little function I stuck in my bashrc, maybe it'll be useful. Uses the .viminfo file to get a list of recently edited files. Obiously not much use unless you use vim as your One True Editor.

vl [-]    # edit most recently edited file
vl [-] 0  # equivalent to above
vl [-] 3  # 4th last edited file (we're 0 indexed)

If $1 is -, show what we'd do but don't do it.

vl() {
 [ "$1" == '-' ] && shift && local echo=echo
 fl=$(awk -v h="$HOME" -v q=${1:-0} '
  $1 == ">" {
   if ( system("test -f " $2) ) next
   if( y++ != q ) next
   sub(/^~/,h,$2)
   print $2
   exit
  }
 ' .viminfo)
 [ "$fl" ] || return
 $echo vim $fl
}
[older]