顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

2013年3月15日 星期五

使用 GitHub 管理 VIM

之前我並沒有在 VIM 裡安裝任何插件 (Plugin),最近開始嘗試使用 VIM 的各種插件,爬文後發現用 GitHub 來管理 VIM 的設定和插件是一件很方便的事。而且,VIM 的配置都放在 $HOME/.vim 這個目錄內,所以也只要同步這個目錄就可以了。

之前在 "使用 pathogen 管理 VIM 的插件 (plugin)" 這篇文章裡,我已經使用 pathogen 來管理 VIM 插件了,使用 pathogen 的好處是只要將插件放到 ~/.vim/bundle 目錄內就行。另外,目前多數的 VIM 插件都集中到 Vim Scripts 這裡,所以只要簡單地搭配 Git Submodule 就可以簡化下載插件的動作。爬了爬文後,似乎很多人都是從 Tsung-Hsiang (Sean) Chang 維護的 vgod's vimrc 開始。vgod's vimrc 確實是一個很棒的範例,所以我也試著研究這個並自己來建立一個屬於自己的 vimrc。

以下這幾篇文章就是使用 pathogen 搭配 Git Submodule 的用法。基本上,Git Submodule 就是將別人的 Repository 當成自己的一部份,所以若來源是 VIM 的插件時,就相當於將 VIM 插件安裝到自己的環境裡。

  1. vgod's vimrc
  2. 使用 Git Submodule 和 Vim-pathogen 管理、同步 Vim 插件及配置
  3. 寶尼: Vim Plugin:GitHub 與 Submodule 共舞

如果將 $HOME/.vim 這個目錄變成一個 Repository,那麼使用 pathogen 搭配 Git Submodule 就很簡單了。只要在 $HOME/.vim 這個目錄內執行這個指令就可以安裝插件了:

$ git submodule add [GIT-REPOSITORY-URL] bundle/[PLUGIN-NAME] 

例如,要安裝 EditPlus 這個插件,而它的來源在 https://github.com/vim-scripts/EditPlus.git,那麼只要執行這一個指令就可以了:

$ git submodule add https://github.com/vim-scripts/EditPlus.git bundle/EditPlus

另外,也可以使用 Vundle 來管理插件。Vundle 的邏輯很有意思,在 Vim Scripts 選好插件後,在 $HOME/.vimrc 裡寫上這麼一行 Bundle [PLUGIN-NAME] ,然後在 VIM 裡執行 :BundleInstall 就搞定安裝的步驟了。下面的文章都有說明怎麼使用 Vundle,也可以直接參考 Vundle 開發者的說明

  1. Git时代的VIM不完全使用教程
  2. 使用github管理VIM

Vundle 的安裝也很簡單,先將 Vundle 下載到 $HOME/.vim/bundle/vundle 目錄:

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

然後在 $HOME/.vimrc 裡加上這段:

set nocompatible       " be iMproved
filetype off          " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'

" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
Bundle 'git://git.wincent.com/command-t.git'
" ...

filetype plugin indent on     " required!
"
" Brief help
" :BundleList          - list configured bundles
" :BundleInstall(!)    - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!)      - confirm(or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle command are not allowed..

其中以 Bundle 開頭的就是要安裝的插件。

所以整理了一下,我決定也試試用 GitHub 來管理我的 VIM,首先在 GitHub 上建立一個名稱為 vimrc 的專案。

接著,在 $HOME/.vim 建立我的 Repository,

$ git init
$ git submodule add git://github.com/tpope/vim-pathogen.git bundle/vim-pathogen
$ git submodule add git://github.com/gmarik/vundle.git bundle/vundle

然後再參考 https://github.com/tpope/vim-pathogenhttps://github.com/gmarik/vundle 的說明,建立 $HOME/.vim/vimrc 這個檔案,然後加入:

runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()

set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
Bundle 'gmarik/vundle'
" My Bundles here:
" vim-scripts repos, vim-scripts.org
Bundle 'SrcExpl'
Bundle 'Trinity'
Bundle 'taglist.vim'
Bundle 'The-NERD-tree'
filetype plugin indent on

接著,將 $HOME/.vim 的內容上傳到 GitHub 去,就搞定了。

$ git add .
$ git commit -m "first commit"
$ git remote add origin https://github.com/yuanfarn/vimrc.git
$ git push -u origin master

往後,在別台 Linux 的電腦上要取用這個 VIM 的設定時,只要依照 https://github.com/yuanfarn/vimrc/blob/master/README.md 的步驟說明下載就可以了。

延伸閱讀

  1. vgod's vimrc
  2. 使用 Git Submodule 和 Vim-pathogen 管理、同步 Vim 插件及配置
  3. 寶尼: Vim Plugin:GitHub 與 Submodule 共舞
  4. Git时代的VIM不完全使用教程
  5. 使用github管理VIM
  6. Windows下安装Vim插件管理Vundle
  7. Git Submodule 的認識與正確使用!

2010年8月15日 星期日

在 Debian / Ubuntu 使用 gitosis 架設 GIT server

首先自套件庫安裝 python-setuptools。

sudo aptitude install python-setuptools

然後自 eagain.net 下載 gitosis 的程式碼。

git clone git://eagain.net/gitosis.git

接著將下載回來的 gitosis 搬移到 /opt 目錄,再到該目錄執行安裝動作。

sudo mv gitosis/ /opt/
cd /opt/gitosis/
sudo python setup.py install

安裝完畢後。接著建立一個使用者 git 以存取 repository。

sudo adduser --system --shell /bin/sh \
--gecos 'git version control' --group \
--disabled-password --home /home/git git

接著以平時使用的帳號產生一組 SSH 的 key。

ssh-keygen -t rsa

再使用這個 SSH key 初始化 Git Server。

sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

接著透過 git 下載 gitosis-admin.git。

git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git

進入下載回來的 gitosis-admin 目錄後,會有一個 gitosis.conf 檔案和一個 keydir 目錄,其中要新增存取 git server 的使用者時,將 SSH key 添加到 keydir 目錄;而 gitosis.conf 則可以用來建立專案。

例如修改 gitosis.conf,添加一個叫 hello 的專案。

--- old/gitosis.conf   2010-08-12 23:08:13.684510792 +0800
+++ new/gitosis.conf 2010-08-12 23:10:55.504778775 +0800
@@ -4,3 +4,7 @@
writable = gitosis-admin
members = online@local

+[group]
+writable = hello
+members = online@local

接著將它送回 git repository,

git commit -a -m "Added a new project \"hello\""
git push

然後就可以開始建立 hello 這個專案了。

mkdir hello
cd hello/
git init
touch README
git add .
git commit -a -m 'Initial import'
git remote add origin git@YOUR_SERVER_HOSTNAME:hello.git
git push origin master