본문 바로가기

TroubleShooting/Mac

mac 기본 환경 설정(vi, ls, color, port, ctags)

728x90

Mac 을 처음사고 터미널을 처음 실행했을때, 하얀 배경화면에 리눅스에서 보던 colorful 한 모양이 안나와서 너무나 당혹스러웠다.


1. 먼저 'ls' 명령어에서  colorful 하게 나오게 하자. 

bash 이 기본 shell 이기 때문에 ".profile" 을 생성하고 아래 내용을 복사한다.

alias ls="ls -FG"

alias h=history

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

PS1='$PWD$ '

export TERM="xterm-color"
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad


2. vim scheme 적용해서 프로그래밍 코드 수정할때 이쁘게 보자. 

- 시스템 전체 사용자에게 적용할때

 예제 scheme 파일이 /usr/share/vim/vim73/(vim 버전이 v7.3) 에 존재한다.

# cd /usr/share/vim

# ls

vim73/     vimrc

# cp vim73/vimrc_example.vim ./vimrc


- 개인 사용자만 적용

 홈 디렉토리로 이동해서 .vimrc 생성 후 아래 내용을 copy&paste 하거나 또는 /usr/share/vim/vim73/vimrc_example.vim 을 .vimrc 로 복사해서 사용한다.

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"

   set fileencodings=ucs-bom,utf-8,latin1
endif

set nocompatible    " Use Vim defaults (much better!)
set bs=indent,eol,start     " allow backspacing over everything in insert mode
"set ai         " always set autoindenting on
"set backup     " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
            " than 50 lines of registers
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  augroup fedora
  autocmd!
  " In text files, always limit the width of text to 78 characters
  " autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
  autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
  " start with spec file template
  autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
  augroup END
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

set shiftwidth=4
set wrapmargin=0
set bs=2
set ts=4 sw=4
set tags=./tags,tags,../tags,../../tags,../../../tags,../../../../tags


3. mac port 설치. 

리눅스 설치관리자같이 port 를 사용하자. 해당 OS 버전(Mountain Lion, Lion, Snow Leopard) 에 맞는 dmg 파일을 선택해서 설치한다.

http://www.macports.org/


4. ctags 교체. 

Mac 에 default 로 설치된 ctags 는 제한된 기능만 제공한다. 개인적으로 가장 많이 사용하는 "-R" 옵션이 없다. 그래서 보통 exuberant ctags 를 설치한다. "port search ctags" 에서 5.8 이라고 나오는 것이 "exuberant ctags" 이다.

# port search ctags

ctags @5.8 (devel)

    Reimplementation of ctags(1)


py-ctags @1.0.5 (python)

    Exuberant Ctags indexing python bindings


py25-ctags @1.0.5 (python)

    Exuberant Ctags indexing python bindings


py26-ctags @1.0.5 (python)

    Exuberant Ctags indexing python bindings


Found 4 ports.

# port install ctags

 install 를 하면 "/opt/local/bin/ctags" 로 설치되는데, 이전 버전은 "/usr/bin/ctags" 에 위치한다. ".profile" 을 작성할때, PATH 에 "/opt/local/bin" 를 먼저 입력했기 때문에 아무 문제없이 새로운 버전 ctags 가 동작한다.


5. 터미널 색깔 변경. 

"터미널 - 환경설정 - 텍스트,윈도우" 에서 원하는 색깔을 선택한다.


이후부터는 터미널에서 리눅스랑 비슷하게 작업할 수 있게 되어, 왠지 심적으로 안정이 온다.