My herbstluftwm configuration

herbstluftwm is the best manual tile window manager I've used.

The default configuration is fine in most cases.

I added hc rules to make some firefox addons usable at my tiny netbook.

So here is my modified $HOME/.config/herbstluftwm/autostart:


# this is a simple config for herbstluftwm

function hc() { herbstclient "$@" }

hc emit_hook reload

xsetroot -solid '#000000'

#feh --bg-scale /home/cb/.config/herbstluftwm/wallpaper.jpg

# keybindings


hc keybind $Mod-Shift-q quit

hc keybind $Mod-Shift-r reload

hc keybind $Mod-Shift-c close

hc keybind $Mod-Return spawn terminator

hc keybind $Mod-x spawn dmenu_run

hc keybind $Mod-q spawn scrot -e 'mkdir -p ~/screenshot;mv $f ~/screenshot/'

# tags

TAG_NAMES=( {1..4} )

TAG_KEYS=( {1..4} 0 )

hc rename default "${TAG_NAMES[0]}" || true

for i in ${!TAG_NAMES[@]} ; do hc add "${TAG_NAMES[$i]}" key="${TAG_KEYS[$i]}" if ! [ -z "$key" ] ; then hc keybind "$Mod-$key" use "${TAG_NAMES[$i]}" hc keybind "$Mod-Shift-$key" move "${TAG_NAMES[$i]}" fi done

# layouting

hc keybind $Mod-r remove

hc keybind $Mod-space cycle_layout 1

hc keybind $Mod-Shift-s split vertical 0.5

hc keybind $Mod-s split horizontal 0.5

hc keybind $Mod-o floating toggle

hc keybind $Mod-f fullscreen toggle

hc keybind $Mod-p pseudotile toggle

# resizing


hc keybind $Mod-Control-h resize left +$RESIZESTEP

hc keybind $Mod-Control-j resize down +$RESIZESTEP

hc keybind $Mod-Control-k resize up +$RESIZESTEP

hc keybind $Mod-Control-l resize right +$RESIZESTEP

# mouse

hc mousebind $Mod-Button1 move

hc mousebind $Mod-Button2 resize

hc mousebind $Mod-Button3 zoom

# focus

hc keybind $Mod-BackSpace cycle_monitor

hc keybind $Mod-Tab cycle_all +1

hc keybind $Mod-Shift-Tab cycle_all -1

hc keybind $Mod-c cycle

hc keybind $Mod-h focus left

hc keybind $Mod-j focus down

hc keybind $Mod-k focus up

hc keybind $Mod-l focus right

hc keybind $Mod-Shift-h shift left

hc keybind $Mod-Shift-j shift down

hc keybind $Mod-Shift-k shift up

hc keybind $Mod-Shift-l shift right

# colors

hc set frame_border_active_color '#49351D'

hc set frame_border_normal_color '#73532D'

hc set frame_bg_normal_color '#BD9768'

hc set frame_bg_active_color '#BD8541'

hc set frame_border_width 0

hc set window_border_width 0

hc set window_border_normal_color '#AE8451'

hc set window_border_active_color '#F6FF00'

# rules

hc unrule -F

#hc rule class=XTerm tag=3 # move all xterms to tag 3

hc rule focus=on # normally do not focus new clients

# give focus to most common terminals

hc rule class~'(.[Rr]xvt.|.*[Tt]erm|Konsole)' focus=on

hc rule windowtype~'NET_WM_WINDOW_TYPE(DIALOG|UTILITY|SPLASH)' pseudotile=on

hc rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' focus=on

hc rule windowtype~'NET_WM_WINDOW_TYPE(NOTIFICATION|DOCK)' manage=off

hc rule instance=xv class=MPlayer fullscreen=on

#firefox dialog should be fullscreen, useful for my tiny eeepc

hc rule instance="Dialog" class="Firefox" fullscreen=on #delicious bookmark

hc rule instance="Aup" class="Firefox" fullscreen=on #autoproxy

hc rule instance="Abp" class="Firefox" fullscreen=on #adblock plus

#view the image in fullscreen

#hc rule instance=feh class=feh fullscreen=on #feh has some bug


hc spawn ~/.config/herbstluftwm/

hc spawn parcellite -nd #use parcellite -p/-c to see the content

xprop is usefult for writing "hc rule". Please man herbstclient. is from the official package. It will display a panel at the top of the screen.

Here is my $HOME/.config/herbstluftwm/ (modified for display batttery rate):



geometry=( $(herbstclient monitor_rect "$monitor") )

if [ -z "$geometry" ] ;then echo "Invalid monitor $monitor" exit 1 fi

# geometry has the format: WxH+X+Y







function uniq_linebuffered() { awk '$0 != l { print ; l=$0 ; fflush(); }' "$@" }

herbstclient pad $monitor $height

{ # events: #mpc idleloop player & while true ; do date +'date ^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d' sleep 1 || break done > >(uniq_linebuffered) & childpid=$! herbstclient --idle kill $childpid } 2> /dev/null | { TAGS=( $(herbstclient tag_status $monitor) ) date="" while true ; do bordercolor="#26221C" hintcolor="#573500" separator="^fg(#141414)^ro(1x$height)^fg()" # draw tags for i in "${TAGS[@]}" ; do case ${i:0:1} in '#') echo -n "^bg(#9fbc00)^fg(#141414)" ;; '+') echo -n "^bg(#9CA668)^fg(#141414)" ;; ':') echo -n "^bg(#6A4100)^fg(#141414)" ;; '!') echo -n "^bg(#FF0675)^fg(#141414)" ;; ) echo -n "^bg()^fg()" ;; esac echo -n "^ca(1,herbstclient focus_monitor $monitor && "'herbstclient use "'${i:1}'") '"${i:1} ^ca()" echo -n "$separator" done echo -n "^bg()^p(_CENTER)" # small adjustments battery=$(expr $(expr $(cat /sys/class/power_supply/BAT/charge_now) * 100) / $(cat /sys/class/power_supply/BAT/charge_full)) if [ "$battery" = "/" ] ;then right="$separator^bg($hintcolor) $date $separator" else right="$separator^bg($hintcolor) $battery% $date $separator" fi right_text_only=$(echo -n "$right"|sed 's.\^[^(]([^)])..g') # get width of right aligned text.. and add some space.. width=$(textwidth "$font" "$right_text_only ") echo -n "^p(_RIGHT)^p(-$width)$right" echo # wait for next event read line || break cmd=( $line ) # find out event origin case "${cmd[0]}" in tag) #echo "reseting tags" >&2 TAGS=( $(herbstclient tag_status $monitor) ) ;; date) #echo "reseting date" >&2 date="${cmd[@]:1}" ;; quit_panel) exit ;; reload) exit ;; #player) # ;; esac done } 2> /dev/null | dzen2 -w $width -x $x -y $y -fn "$font" -h $height \ -ta l -bg "$bgcolor" -fg '#efefef'

gitorious is useless

It's too hard to get code from gitorious. I tried git clone from gitorious's server for half an hour and failed. My similar operation on github usually succeeded (I am at Shanghai/China). I would not panic if I could copy code from its web page. And I couldn't! Gitorious screwed up my clipboard by mixing the line number in! Horrible frontend UI design. Select/copy code is easy at github is easy.

Emacs gdb/gud hotkeys

Please note if you're using Emacs 24 on OS X 10.7.3, you need M-x gud-gdb instead M-x gdb to start debug session.

It's because M-x gdb assume gdb 7.x installed while there is actually only gdb 6.3 installed.

  • C-x C-a C-d gud-remove
  • C-x C-a C-b gud-break
  • C-x C-a C-g gud-run (customized by me)
  • C-x C-a C-p gud-print
  • C-x C-a C-r gud-continue



  • 可能导致静脉曲张
  • 建议一小时休息一次
  • 游泳,活动膝盖有助于减少副作用
  • 一个酒吧使用的高的椅子是必需的,可以随时休息
  • 好的鞋,踩在垫子上,防止受伤


Sample python code to resize image

import Image

import cStringIO


# in real application, I handle the data in memory



print "DONE"

mysqldump for sqlite3

Be careful that import data into Sqlite3 could be very slow in this way.

mysqldump -u root -p111111 -c --compact -t --skip-opt dbname tbl1 tbl2|sed -e "s/\'/''/g"|gzip -9 > data.dump.gz
zcat data.dump.gz | sqlite3 db.sqlite3

My Emacs configuration


  • support c++/python/perl/ruby-on-rails/javascript
  • eim (Chinese Pinying IME for emacs)
  • org2blog (post wordpress blog by org-mode)


git clone ~/.emacs.d;

Some plugins need be compiled for better performance (OPTIONAL)

  • cedet,ecb,emacs-w3m,org-mode,nxml-mode,mmm-mode,auto-complete
cd ~/.emacs.d/site-lisp;make -C cedet;make -C ecb;make -C org-mode;make -C nxml-mode;make -C auto-complete

cd ~/.emacs.d/site-lisp/emacs-w3m;autoconf;./configure;make;sudo make install-info-en;

cd ~/.emacs.d/site-lisp/mmm-mode;./;./configure;make;sudo make install-info;


  • rinari (install info only)
cd ~/.emacs.d/site-lisp/rinari;rake doc:make_info;sudo cp doc/ /usr/share/info;sudo install-info /usr/share/info/ /usr/share/info/dir

  • eim
cd ~/.emacs.d/site-lisp/eim;emacs -batch -f batch-byte-compile *.el;


  • 列编辑C-x r t yourstring RET (参见How to do select column then do editing in GNU Emacs ?)
  • 记录当前位置到register中 C-r SPC (需安装better-registers.el,且要注释掉其中对快捷键'C-x r'的占用)
  • 跳转至某register, C-j (需better-registers.el)
  • Save frame configuration to register, C-r f (要求同上)
  • Comment current line, M-; (需qiang-comment-dwim-line)
  • Visit the next/previous error message, M-g M-n/M-p
  • find-tag/pop-tag-mark, M-./M-*
  • M-x lgrep/rgrep, grep CWD only or all sub-directories
  • M-x visit-tags-table, give you choice on multiple tags table
  • M-x org-timer-set-timer, C-c C-x ;, set count down timer
  • M-x org-mark-subtree, 选中org-mode中的subtree

Perforce Tip: how to apply my default change to the release branch

Reasons I need this hack

  • Our current project used mix platforms (WIN64/Linux64), so the file path contains backward slash \.
  • My p4 CLI program is from Windows installer because Cygwin version has the slash issue.
  • Windows version of p4 has no such issue under Cygwin if we only feed it relative path.

How to?

Create the patch,

p4 diff -du -db main-branch/... > ~/mywork.patch

Go to the work directory of release branch.

cd dir-release-branch/

p4 edit' the files I want to patch under release branch. Please note, </p><ul> <li>lsdiff' is from the package patchutils'. </li> <li>nosl' will strip the backward/forward slashes. It's written by me.

cat ~/mywork.patch|lsdiff|nosl 5|p4 -x - edit

Patch the files and DONE!

patch -p5 < ~/mywork.patch

Here is the source code of nosl. I put it in my .bashrc

nosl ()

{ if [ -z "$1" ]; then echo "Usage: echo /hello/world|nosl num"; echo "strip num leading slashes"; else perl -pe "\$n=$1;while(\$n>0){ \$_=~ s/[^\\\/]*[\\\/]+//;\$n--; }"; fi }

BTW, you could avoid all the trouble of Perforce by switching to Git.

multiple ssh private keys