Aiur – ZelluX 的技术博客

Security, Kernel, Virtualization, Programming Languages

Archive for the ‘Tools’ Category

记录GNU screen中的历史命令

10 views | without comments

GNU screen中执行的历史命令保存在内存中,默认情况下并不会像在bash中直接执行的命令一样保存在.bash_history中,这在某些场合下带来了一定的不便。

在superuser上看到一个解决方法,指定历史文件的读写方式为追加,并在每次命令行提示符显示的时候,自动更新bash的历史命令记录。要实现这个方法很简单,只要在.bashrc中加入下面两行代码即可

shopt -s histappend
export PROMPT_COMMAND="history -a; history -n"

另外如果之前设置过PROMPT_COMMAND的话,只要在history -a前加入$PROMPT_COMMAND; 就行了。

Written by zellux

March 1st, 2010 at 12:14 am

Posted in Tools

Tagged with , ,

优化gitk的字体显示

15 views | with 2 comments

gitk是用Tcl/Tk写的工具,默认使用Tk 8.4,不支持抗锯齿,因此字体显示很难看。好在Tk 8.5支持了部分抗锯齿字体,修改gitk使用Tk 8.5后显示效果会好一点。

以Ubuntu为例,安装tk8.5包后,编辑/usr/bin/gitk文件,把开头调用wish的那行

exec /usr/bin/wish "$0" -- "$@"

改成

exec /usr/bin/wish8.5 "$0" -- "$@"

这样就能在gitk中开启抗锯齿了,虽然效果还不是很好。另外qgit也是一个不错的选择。

参考链接:http://navarra.ca/?p=44

Written by zellux

February 14th, 2010 at 7:08 pm

Posted in Tools

Tagged with ,

WPtouch

4 views | without comments

这是一个让wordpress对移动设备更友好的插件,下载地址在http://wordpress.org/extend/plugins/wptouch/,当然也可以在wordpress后台查找wptouch并安装。

在iPod Touch上的效果图

Written by zellux

February 13th, 2010 at 1:52 pm

Posted in Tools

Tagged with ,

ecb和cscope的结合使用

14 views | without comments

前几天试用了下ECB,非常喜欢它的定义列表和文件浏览历史的功能。但是却发现了另外一个问题:使用ECB之前我把整个窗口分成左右两块,左边是代码,右边是cscope的查找结果,现在开启ECB之后就不能再切一块窗口给cscope用了。

感谢stackoverflow上的sanitynic,给出了自定义ECB窗口的参考。现在俺终于能把cscope窗口绑定到屏幕左下角啦。

自定义ECB layout其实也挺方便的,上图对应的配置为

(ecb-layout-define "my-cscope-layout" left nil
                   (ecb-set-methods-buffer)
                   (ecb-split-ver 0.5 t)
                   (other-window 1)
                   (ecb-set-history-buffer)
                   (ecb-split-ver 0.25 t)
                   (other-window 1)
                   (ecb-set-cscope-buffer))

(defecb-window-dedicator ecb-set-cscope-buffer " *ECB cscope-buf*"
                         (switch-to-buffer "*cscope*"))

(setq ecb-layout-name "my-cscope-layout")

;; Disable buckets so that history buffer can display more entries
(setq ecb-history-make-buckets 'never)

my-cscope-layout这个layout左边窗口分为三部分,最上面的函数列表占一半高度,中间为历史文件列表,下面为cscope的查找结果,它们各占四分之一的高度。

另外再简单提下cscope插件的安装和配置,使用前需确认当前系统已经安装了cscope,另外要有cscope-indexer这个脚本。在cscope/contrib目录下找到一个xcscope.el,复制到Emacs的插件目录中,并在Emacs初始化文件中加入

(require 'xcscope)

即可。某些发行版的包里面似乎没有cscope-indexer和xcscope.el,直接从网上下一个好了。

几个常用的快捷键:
C-c s I 建立cscope索引
C-c s a 设置搜索目录
C-c s d 查找定义
C-c s s 查找字符串
C-c s c 查找调用者
C-c s n 下一个查找结果
C-c s p 上一个查找结果
更多的快捷键可以通过C-h b在cscope-minor-mode区找到。

Written by zellux

February 7th, 2010 at 11:30 pm

Posted in Tools

Tagged with , ,

为特定的项目配置semantic

38 views | without comments

semantic是cedet的组件之一,它可以对程序做语义分析,结合company等其他插件,可以实现自动补全菜单等功能。

之前用semantic+company写MIT 6.828的lab时几乎不需要什么特殊的设置就能直接用了,这次拿来改Xen的代码的时候却出现了semantic无法找到符号定义的问题,究其原因在于MIT 6.828的目录结构相对简单,头文件都在inc/目录下,而Xen的头文件在多个目录下,而且做预处理时还要加上Makefile里定义的一些预定义宏。今天参考了Alex Ott的这篇文章终于成功地让semantic支持Xen的代码分析了:

这里分享一下和项目相关的一些设置,semantic安装等问题请参考网上的其他文章。也可以参考我的配置文件http://code.google.com/p/zellux-emacs-conf/source/browse/my-cc-mode.el,cscope ecb semantic和company等配置都在这个文件里了,不过有点混乱。

;; Danimoth-specified configurations
(add-to-list 'semanticdb-project-roots "~/danimoth/xen")

(setq semanticdb-project-roots
      (list
       (expand-file-name "/")))

(setq danimoth-base-dir "/home/wyx/danimoth")

(add-to-list 'auto-mode-alist (cons danimoth-base-dir 'c++-mode))
(add-to-list 'auto-mode-alist (cons danimoth-base-dir 'c-mode))

(add-to-list 'semantic-lex-c-preprocessor-symbol-file (concat danimoth-base-dir "/xen/include/config.h"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-file (concat danimoth-base-dir "/xen/include/asm-x86/config.h"))

(ede-cpp-root-project "Danimoth"
                      :name "Danimoth"
                      ;; Any file at root directory of the project
                      :file "~/danimoth/xen/Makefile"
                      ;; Relative to the project's root directory
                      :include-path '("/"
                                      "/include/asm-x86"
                                      "/include/xen"
                                      "/include/public"
                                      "/include/acpi"
                                      "/arch/x86/cpu/"
                                      )
                      ;; Pre-definds macro for preprocessing
                      :spp-table '(("__XEN__" . "")
                                   ))

其中,/home/wyx/danimoth/xen是项目的主目录,xen/include/config.h和xen/include/asm-x86/config.h里定义了一些基本的宏。

接下来,ede-cpp-root-project指定了这个项目的其他信息:
:file 指向项目主目录下任一一个存在的文件
:include-path 指定头文件的所在目录
:spp-table 给出了预处理时的使用的宏,通常是在Makefile里使用-DXXX定义的宏,例如这里的__XEN__。

配置好semantic后,可以用M-x semantic-ia-complete-symbol测试。如果Emacs能正确显示补全列表,这就说明semantic已经配置成功了。配合这个简单的company设置,就能用Shift-Tab显示类似图片中的自动补全菜单了。

Written by zellux

February 3rd, 2010 at 3:30 pm

Posted in Tools

Tagged with ,

ECB的简单配置和使用

40 views | with 3 comments

终端下的效果图(Windows 7下使用pietty远登)

ECB Terminal

下载

http://ecb.sourceforge.net/downloads.html CVS或者压缩包都可以,当然也可以通过各发行版的包管理器安装。

安装

在.emacs中加入

;; ECB configurations
(add-to-list 'load-path "~/emacs/ecb-2.40")
(add-to-list 'load-path "~/emacs/cedet-1.0pre6/eieio")
(add-to-list 'load-path "~/emacs/cedet-1.0pre6/semantic")
(add-to-list 'load-path "~/emacs/cedet-1.0pre6/speedbar")
(setq semantic-load-turn-everything-on t)
(require 'semantic-load)
(require 'ecb-autoloads)

运行Emacs后执行ecb-byte-compile,并重启Emacs(我这里不重启的话执行ecb-active后会报错)。

使用

第一次使用时先要设置项目目录,M-x customize-variable <RET> ecb-source-path <RET>,在这里加上你的项目根目录。

接下来使用M-x ecb-active就能激活ECB了,成功激活后Emacs窗口会被切成左右两半。左边的几个窗口依次显示:目录,当前目录下的文件,当前文件中的函数/全局变量等定义,文件浏览历史。如果打开了一个源文件后函数定义窗口里面是空的,有可能是因为这个项目过大cedet尚未完成对它的分析,闲置一段时间后就能看到文件里的定义。

ECB提供了方便在这些窗口间切换的快捷键:

切换到目录窗口 Ctrl-c . g d
切换到函数/方法窗口 Ctrl-c . g m
切换到文件窗口 Ctrl-c . g s
切换到历史窗口 Ctrl-c . g h
切换到上一个编辑窗口 Ctrl-c . g l

最基本的使用就是这样,Ctrl-C . h可以看到更详细的帮助信息。

Written by zellux

February 2nd, 2010 at 4:52 pm

Posted in Tools

Tagged with ,

Git命令行自动补全

12 views | without comments

Pro Git上看到的技巧,git的源代码包里的contrib/completion目录下有个git-completion.bash,把这个文件保存到~/.git-completion.bash,然后在.bashrc中加入一行

source ~/.git-completion.bash

这样就能在bash下用tab自动补全git命令、branch等内容了。另外Debian/Ubuntu里有个包就叫git-completion,这个包安装完成后会自动把这个补全脚本放到/etc/bash_completion.d/下,由bash-compleletion载入执行。

Written by zellux

January 25th, 2010 at 3:45 pm

Posted in Tools

Tagged with

使用grep查找进程的技巧

10 views | without comments

使用grep在ps aux的输出结果中查找进程的时候经常会把grep进程本身也找出来,比如查找emacs进程:

$ ps aux | grep emacs
wyx   7090  0.0  0.0   3336   796 pts/2 S+ 04:49 0:00 grep emacs
wyx  10128  0.1  4.9  66904 50388 pts/3 S+ Jan21 2:21 emacs

一个常见的防止grep进程出现的方法就是在后面再加一个grep -v grep:

$ ps aux | grep emacs | grep -v grep
wyx  10128  0.1  4.9  66904 50388 pts/3 S+ Jan21 2:21 emacs

今天在Santosa的博客上看到了另一个巧妙的做法,使用grep [e]macs来搜索emacs这个进程:

$ ps aux | grep [e]macs
wyx  10128  0.1  4.9  66904 50388 pts/3 S+ Jan21 2:21 emacs

为什么会有这样的效果,知道grep正则中[]的作用后想一想就能明白啦。很有意思的trick,虽然说它比grep -v grep也未必方便多少,因为后者能通过alias简化输入。

Written by zellux

January 21st, 2010 at 8:47 pm

Posted in Tools

Tagged with ,

Ubuntu下编译Linux-xen的问题

2 views | without comments

在Ubuntu下编译Linux-xen时碰到arch/i386/kernel/head-xen.o无法找到的问题,而该目录下有head-xen.S这个文件,说明make之前的的工作并没有把这个.S文件编译成.o。而同样的代码,在ArchLinux和Fedora上svn checkout后编译没有任何问题。

最后发现问题在于Ubuntu默认会把/bin/sh指向/bin/dash,在scripts/Makefile.build里面加上一行SHELL=/bin/bash指定$(shell)使用bash即可。后来还搜了一下为什么Ubuntu使用dash而不是bash,其理由是dash的执行效率更高,但不可否认的是这个改动也导致了一些项目无法成功编译,虽然无法成功编译的原因可能是Makefile里使用了一些bash的特性而非POSIX shell所提供的那些。

另外在debug过程中在网上找到了一些debug Makefile的技巧:

make -n 可以仅仅打印出将要被执行的命令,而不去实际执行

make -np 可以打印出更多的信息(使用的规则和变量),并执行每一条命令

remake也是个不错的选择:“remake is a patched and modernized version of GNU make utility that adds improved error reporting, the ability to trace execution in a comprehensible way, and a debugger.”

在检查shell命令的时候,可以使用set -x使得所有shell命令在执行前都能被输出。

Written by zellux

December 17th, 2009 at 2:41 pm

Posted in Tools

Tagged with , ,

Emacs中对不同项目指定不同的风格

8 views | without comments

我的Emacs配置里C语言默认的缩进风格是用4个空格,最近要修改Chromium的代码,而Google的C/C++风格统一为2个空格缩进,所以改代码的时候要把c-basic-offset设置为2。这样在不同项目间切换的时候很不方便。

stackoverflow上发帖求助后发现了Emacs 23.1一个很好用的新功能,Per-Directory Local Variables,只需要在项目主目录下放一个.dir-locals.el文件,里面设置该项目特有的变量值,就能应用到整个项目了。

以我的Chromium为例,Google已经提供了一份C/C++风格的配置,只需要在~/chromius/src/.dir-locals.el里把google-c-style常量粘贴进去即可。另外我不知道为啥加上c-offsets-alist那段后Emacs缩进会变得很奇怪,所以我把它删了。附修改后的.dir-locals.el

((c++-mode . ((c-recognize-knr-p . nil)
              (c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs
              (c-basic-offset . 2)
              (indent-tabs-mode . nil)
              (c-comment-only-line-offset . 0)
              (c-hanging-braces-alist . ((defun-open after)
                                         (defun-close before after)
                                         (class-open after)
                                         (class-close before after)
                                         (namespace-open after)
                                         (inline-open after)
                                         (inline-close before after)
                                         (block-open after)
                                         (block-close . c-snug-do-while)
                                         (extern-lang-open after)
                                         (extern-lang-close after)
                                         (statement-case-open after)
                                         (substatement-open after)))
              (c-hanging-colons-alist . ((case-label)
                                         (label after)
                                         (access-label after)
                                         (member-init-intro before)
                                         (inher-intro)))
              (c-hanging-semi&comma-criteria
                . (c-semi&comma-no-newlines-for-oneline-inliners
                    c-semi&comma-inside-parenlist
                    c-semi&comma-no-newlines-before-nonblanks))
              (c-indent-comments-syntactically-p . nil)
              (comment-column . 40)
              (c-cleanup-list . (brace-else-brace
                                  brace-elseif-brace
                                  brace-catch-brace
                                  empty-defun-braces
                                  defun-close-semi
                                  list-close-comma
                                  scope-operator)))))

Written by zellux

December 1st, 2009 at 4:05 pm

Posted in Tools

Tagged with

FireStats icon Powered by FireStatsBetter Tag Cloud