2012年4月16日 星期一

Recovery tmux socket file

Tmux is a very powerful and useful tool. I use it everyday. But it's default path for socket file is /tmp and our development will clean /tmp periodical and cause socket file lost. The way to recreate socket file is send a signal SIGUSR1 to tmux to ask recreate socket file. It's helpful when you accidentally remove it or any unknown broken on socket file.

command:
kill -USR1

2012年3月10日 星期六

在tcsh bash上使用vim,emacs key binding

在unix系統裡很多人都會使用emacs或vim這兩種歷史悠久又很受歡迎的編輯器。這兩種編輯器的鍵盤設定也很有各自強烈的特色。在各有龐大的使用者基礎下,許多的軟體(尤其是unix上的軟體)就常提供這兩種編輯器鍵盤設定作為他們的操作設定。

即使你不使用emacs或vi,熟悉任一種操作設定也很有幫助,因為那就 等同於你熟悉了一種通用操作方式。例如less支援vi鍵盤操作, gdb, bash, tcsh都同時支援vi及emacs的操作方式。就連各個瀏覽器也都有人試著使用這兩種操作方式來操作。

先不提未來的種種優點,至少第一步在shell的輸入上,你就能獲得立即的好處。


Tcsh:
Tcsh的key binding預設是emacs style
列出目前設定:bindkey
設定為emacs鍵盤操作: bindkey -e
設定為vi鍵盤操作: bindkey -v

Bash
Bash 預設key binding也是emacs style
列出目前設定:bind -p
設定為emacs鍵盤操作: set -o emacs
設定為vi鍵盤操作: set -o vi


如果你真的都不熟,對照著下面相關資料裡提供的速查表,練習一下很快就能記住。下面連結中是以bash說明,tcsh除了設定的指令不同外,鍵盤操作當然是大致相同。別忘了,我們就是想熟悉一種可以通用的操作方式。



2011年8月29日 星期一

git svn比svn client好用

最近和慣用svn的人合作一個專案,才發現我己經很不習慣svn還有他每次都要和server連線速度,於是改用git svn。使用時要push回svn要小心一點,但是還是覺得比svn client好用。現在己經離不開git了。

2011年4月20日 星期三

Essential vim plugin - EasyMotion

I found a very handy vim plugin EasyMotion recently. It extend the original vim motions command like 'w', 'e', 'b', and 'f' and provide a new way to move to any position in screen according your selection.

The story is vim provides very powerful motion like move a word forward, back or jump to next character you typed and you can control how many times of move by '5w', '3b', or '3fk'. It's useful when scripting but not for visual operation. Does anyone count how many words before you move cursor? But it is handy when move one or two word forward or back but not move to the word half page away.

I have same problem too, especially in terminal. Actually I never use vim gui. I know where the target is in screen but need to move row and move character or word. I believe most people move cursor and observe the change rather count how many 'w' you should use.

Mouse support can help this. Click on a position and change cursor to there. But you have to move you hand out of keyboard and click and back to keyboard and not every terminal support mouse.

This plugin can help on this. You can use 'w', 'e', 'b', or 'f' to move by word or move to target character and then it show ALL matched position of screen and mark the position with a character. You press the character according visual mark and move cursor to there just like mouse click and don't need to move your hand away from keyboard.

My description make you confuse? Just check the demo and start to use it.

2010年7月11日 星期日

Integrate vim and lxr

LXR is the Linux cross reference which a "a software toolset for indexing and presenting source code repositories" (from lxr web site). It's very useful when you develop large software system with big team. There always are apis you never know and don't know how to use it or data object you need to check what's it exactly provided. But it provide web base interface and I want use it in my vim.

There is another advantage for me to integrate lxr and vim. Our team rebuild the lxr database to refresh member's update automatically and I don't have to update index database like cscope by myself which I did it past two years.

The way I integrate vim and LXR is quite simple. I think maybe it's just too simple and I can't find any related information from internet. Anyway, I made it myself and it does help to me.

I integrate the vim and LXR by provide a utility which send http request to LXR web server, parser the http response, and translate to cscope's line-oriented output. Then, the vim can interactive with cscope by line-oriented mode. It's so simple that you can even use shell script to make it and I made it with python. Actually it's a cscope line-oriented mode enumerator for LXR. :-) The other benefit is emacs can use it too.

The MOST IMPORTANT THING is that prompt of cscope is ">> ". Note the last space character. It's part of prompt. The space take me one day to debug. I even read the vim and global source code. You can avoid the stupid bug if you read my blog. It's OK to skip all other part of this article when you note this. :-)

Then, not all cscope functions can map to LXR. For example, cscope can only search who call a function or everyone called by a function. But the LXR provide all reference only. My team use older version's LXR and it provide less information then latest.

The last thing is LXR can tell you a line of a source file reference to the keyword you search but no code segment. You have to check each result You can either send another http request to LXR web server to get code segment or grep source file according to the file path provided by search result. The code segment is very very helpful when you get large search result.

2010年6月7日 星期一

Add font without root in linux

My job is software development in Linux. Our company provide many servers for development. Of curse, I don't have root permission. But I want some great font for coding and that really help a lot. So I try to use font in my terminal without root permission.

Step:
1.put font file into .fonts in your home directory
2.run "fc-chace" update font cache. And you can check the font list with "fc-list"
3.set your application such gvim or terminal to the font you add.
That's all.

Linux Tutorial: Linux Fonts have detail information about fonts in linux.

2010年6月5日 星期六

Manul build Atheros AR8151 for ArchLinux

Well... This also take me couple hours. It shouldn't' be. So I need to note it for myself.

First, there is not build-in support for atheros AR8151 ethernet chip in archlinux. You need to build it by yourself.

2.extract tar ball to somewhere.
3.make sure you have related package like gcc, make, kernel header.
4.The driver from atheros default take /lib/modules/$(BUILD_KERNEL)/build for kernel header and I change to /usr/src/linux-$(BUILD_KERNEL) by change the order of KSP variable in src/Makefile
5.Refer to readme file in tar ball, I found I don't have version.h in header path and do "make include/linux/version.h" in linux source tree.
6.I use kernel 2.6.33 and it seems have a change which not use utsrelease.h file. But the driver makefile need it. I manually add a utsrelease.h in /usr/src/$(KERNEL_VERSION)/include/linux with content "#define UTS_RELEASE 2.6.33-ARCH"
7.build driver with "make" and "make install" to install it (don't forget install as root)
8.You should get a driver as kernel module in /lib/modules//kernel/drivers/net/atl1e/atl1e.ko. The readme file of tar ball show it as arl1e.ko but I get alt1e.ko. I don't know why but it don't matter. It's the driver for AS8151.
9.load the driver by "modprobe atl1e" and check it with "lsmod | grep atl1e"
10.Finish to build driver. You can test it by "ifconfig ethx

Then the AR5181 ethernet chip works. And don't forget to add it to MODULE of /etc/rc.conf or config modprobe for next boot.