2008-03-10
osx での開発環境整備
.vimrc に has('macunix') とか .zshrc に if [ "$OSX" ] とかが現れるようになった。
rascut trunk + vim as3 な開発ができるところまではやった。vim でのタグスキャンがやたら遅い気がする。Terminal.app なのにもっさりしてる気がする。putty on vmware fusion の方が速い!Chemr もうまく起動しないしこれもふつうに vmware で chm 読んだ方が手っ取り早い気がするがそれならわざわざ osx つかわなくてもいいよねーということでもうちょっとがんばろう。
git の branch を vim のステータスラインに表示
let g:gitCurrentBranch = ''
function! CurrentGitBranch()
    let cwd = getcwd()
    cd %:p:h
    let branch = matchlist(system('/usr/bin/git  branch -a --no-color'), '\v\* (\w*)\r?\n')
    execute 'cd ' . cwd
    if (len(branch))
      let g:gitCurrentBranch = '][git:' . branch[1] . ''
    else
      let g:gitCurrentBranch = ''
    endif
    return g:gitCurrentBranch
endfunction
autocmd BufEnter * :call CurrentGitBranch()
set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff}%{g:gitCurrentBranch}%{']'}%y\ %F%=%l,%c%V%8P
git の branch を rprompt に表示 ( と zsh の chpwd なんかをひとつにまとめる)
branch わからないと不安になってくるので表示るように。typo さんの真似。ただ refs とか長いのはいらないので git-branch コマンドで。0.001秒以下で終わるので毎回 chpwd 時に走ってもいいや感。
また、zsh 4.3.4 から入った zsh-templates を使ってみる。( http://xanana.ucsc.edu/~wgscott/wordpress_new/wordpress/?p=12 ) これ使うと preexec や chpwd がすっきりかけていいね。
typeset -ga chpwd_functions
function _screen_title_chpwd() {
  if [ "$TERM" = "screen" ]; then
    echo -n "^[k[`basename $PWD`]^[\\"
  fi
}
functions _set_rprompt_git() {
  local -A git_res
  git_res=`/usr/bin/git branch -a --no-color 2> /dev/null `
  if [ $? != '0' ]; then
    RPROMPT=$RPROMPT_DEFAULT
  else
    git_res=`echo $git_res|grep '^*'|tr -d '\* '`
    RPROMPT=' %{^[[32m%}('$git_res')%{^[[00m%} '$RPROMPT_DEFAULT
  fi
}
functions _xxx_ls() {
  ls
}
chpwd_functions+=_xxx_ls
chpwd_functions+=_screen_title_chpwd
chpwd_functions+=_reg_pwd_screennum
chpwd_functions+=_set_rprompt_git
今日の .vimrc さん
:Bgrep foo で開いてるバッファから検索。いちいち :bufdo vim /foo/j % するのがめんどくさくなったのと、例外が開いてるものによっては発生するのが嫌だったので関数化。
function! Bgrep(word)
  cexpr '' " quickfix を空に
  silent exec ':bufdo | try | vimgrepadd ' . a:word . ' % | catch | endtry'
  silent cwin
endfunction
command! -nargs=1 Bgrep :call Bgrep()
